引用值及其后的值
Referencing value and values after it
假设我有一个列表:
list1 = [1,2,3,4,5,6,7,8,9,10]
我想要一个循环,对于每个值,检查它的串联版本和它以外的任何其他版本是否与另一个列表中的现有值相同。说得通?不?这是我想说的。
列表
list1 = ['3','ex','fish nets','orange','banana','exampl','apple']
list2 = ['e','x','blah','exam','p','l','blahblah']
最后,我们采用这些列表,假设我每次都希望一个值和它后面的任何相邻数量的值等同于 list1
中的一个值,以便将它们连接起来。 (即值 e 和 x 连接为存在于 list1
中的 ex。)因此,它将 list2
修改为:
list2 = ['ex','blah','exam','p','l','blahblah']
同样适用于三个或四个或列表中的许多值。该循环将重新检查其余可能的组合(仅左 -> 右)并执行相同的操作。 exam、p 和 l 连接到 list1
[=31= 中的值]示例。 list2
然后变成:
list2 = ['ex','blah','exampl','blahblah']
这方面的措辞很糟糕,但我希望这些示例足够深入,能够表达我的需要。
list1 = ['3','ex','fish nets','orange','banana','exampl','apple']
list2 = ['e','x','blah','exam','p','l','blahblah']
a=list2
j=['e','x','blah','exam','p','l','blahblah']
t=[]
for y in range(0, len(j)):
for i in range(1,len(j)-y):
r=''
t=j[y:y+i+1] #Create a list of adjacent elements.
for x in t:
r+=str(x) #make it string and check if it fits.
if r in list1:
list2[y]=r
for e in range(y+1,y+i+1):
list2[e]=0 # to avoid a mess with indexes.
while 0 in list2:
list2.remove(0)
print list2
我知道它很笨拙,但它似乎有效。
假设我有一个列表:
list1 = [1,2,3,4,5,6,7,8,9,10]
我想要一个循环,对于每个值,检查它的串联版本和它以外的任何其他版本是否与另一个列表中的现有值相同。说得通?不?这是我想说的。
列表
list1 = ['3','ex','fish nets','orange','banana','exampl','apple']
list2 = ['e','x','blah','exam','p','l','blahblah']
最后,我们采用这些列表,假设我每次都希望一个值和它后面的任何相邻数量的值等同于 list1
中的一个值,以便将它们连接起来。 (即值 e 和 x 连接为存在于 list1
中的 ex。)因此,它将 list2
修改为:
list2 = ['ex','blah','exam','p','l','blahblah']
同样适用于三个或四个或列表中的许多值。该循环将重新检查其余可能的组合(仅左 -> 右)并执行相同的操作。 exam、p 和 l 连接到 list1
[=31= 中的值]示例。 list2
然后变成:
list2 = ['ex','blah','exampl','blahblah']
这方面的措辞很糟糕,但我希望这些示例足够深入,能够表达我的需要。
list1 = ['3','ex','fish nets','orange','banana','exampl','apple']
list2 = ['e','x','blah','exam','p','l','blahblah']
a=list2
j=['e','x','blah','exam','p','l','blahblah']
t=[]
for y in range(0, len(j)):
for i in range(1,len(j)-y):
r=''
t=j[y:y+i+1] #Create a list of adjacent elements.
for x in t:
r+=str(x) #make it string and check if it fits.
if r in list1:
list2[y]=r
for e in range(y+1,y+i+1):
list2[e]=0 # to avoid a mess with indexes.
while 0 in list2:
list2.remove(0)
print list2
我知道它很笨拙,但它似乎有效。