# 如何匹配两个长度相同的列表

[英]How to match two list with the same length

``````   df = [[[1, 5,7,9,12,13,17],
[2,17,18,23,32,34,45],
[3,5,11,33,34,36,45]],
[[6,21,22,50,56,58,72],
[7,5,12,13,55,56,74],
[8,23,24,32,56,58,64]]]

df2 = [[[100,5,12,15,27,32,54],
[120,10,17,18,19,43,55],
[99,21,32,33,34,36,54]],
[[41,16,32,45,66,67,76],
[56,10,11,43,54,55,56],
[77,12,16,18,19,21,23]]]

``````

``````    output = [[[[5,12,],[17]],
[[17,18],[32,34,36]]],
[[[55,56],[32]],[[56]]]
``````

``````df = [
[[1, 5, 7, 9, 12, 13, 17], [2, 17, 18, 23, 32, 34, 45], [3, 5, 11, 33, 34, 36, 45]],
[[6, 21, 22, 50, 56, 58, 72], [7, 5, 12, 13, 55, 56, 74], [8, 23, 24, 32, 56, 58, 64]],
]

df2 = [
[[100, 5, 12, 15, 27, 32, 54], [120, 10, 17, 18, 19, 43, 55], [99, 21, 32, 33, 34, 36, 54]],
[[41, 16, 32, 45, 66, 67, 76], [56, 10, 11, 43, 54, 55, 56], [77, 12, 16, 18, 19, 21, 23]],
]

sequences_1 = []

for el in df:
for lis in el:
length = len(lis)
for i in range(0, length):
for n in range(i + 1, length + 1):
sequences_1.append(lis[i:n])

sequences_2 = []

for el in df2:
for lis in el:
length = len(lis)
for i in range(0, length):
for n in range(i + 1, length + 1):
sequences_2.append(lis[i:n])

matches = set()

for seq_1 in sequences_1:
for seq_2 in sequences_2:
if seq_1 == seq_2:
print(matches)
``````

``````{(5,), (11,), (17,), (23,), (17, 18), (32,), (55, 56), (56,), (5, 12), (34, 36), (34,), (33, 34, 36), (55,), (33, 34), (12,), (18,), (21,), (33,), (36,), (45,)}
``````

[英]match length of string with a string with the same length in a list

2013-04-11 13:05:52 1 56   match

[英]Comparing two lists not with same length, finding matches and appending the match with value from first list

2015-02-16 02:36:35 4 741   list

[英]how to match two numpy array of unequal length?

2011-09-12 06:56:43 5 1816   numpy

[英]How to merge two lists of the same length, and retain the length by replacing values

2020-07-15 21:45:05 4 103   pandas

[英]How to add two list with different length?

2020-02-22 17:46:20 1 60   numpy

[英]How to match two columns from different Dataframes and with different length?

[英]how to merge two dataframes if the index and length both do not match?

2016-08-23 16:48:12 1 521   pandas