如何在 python 中形成给定的元素列表以从中创建另一组列表?
How to form a given list of elements in python to create another set of lists from it?
List1 =['000095', '000094', '000092', '000101', '000099', '000096', '000095']
def makecycle(list, startElement):
一个循环,由上面的元素构成底部列表!
如果我将起始元素和列表传递给该函数,它应该像这样打印:
makecycle(list1, 000094) it should print:
['000094', '000092', '000101', '000099', '000096', '000095', '000094']
and if pass
makecycle(list1, 000101) it should print:
['000101', '000099', '000096', '000095', '000094', '000092', '000101']
and if pass
makecycle(list1, 000092) it should print:
['000092', '000101', '000099', '000096', '000095', '000094', '000092']
我知道它有点不够清楚,但我只能指出这些!
def makecycle(list1,startElement):
ind = list1.index(startElement)
l = len(list1)
i = ind
list2 = []
while ind < (l-1):
list2.append(list1[ind])
ind = ind + 1
for x in range(i):
if list1[x] not in list2:
list2.append(list1[x])
print(list2)
List1 =['000095', '000094', '000092', '000101', '000099', '000096', '000095']
def makecycle(list, startElement):
一个循环,由上面的元素构成底部列表!
如果我将起始元素和列表传递给该函数,它应该像这样打印:
makecycle(list1, 000094) it should print:
['000094', '000092', '000101', '000099', '000096', '000095', '000094']
and if pass
makecycle(list1, 000101) it should print:
['000101', '000099', '000096', '000095', '000094', '000092', '000101']
and if pass
makecycle(list1, 000092) it should print:
['000092', '000101', '000099', '000096', '000095', '000094', '000092']
我知道它有点不够清楚,但我只能指出这些!
def makecycle(list1,startElement):
ind = list1.index(startElement)
l = len(list1)
i = ind
list2 = []
while ind < (l-1):
list2.append(list1[ind])
ind = ind + 1
for x in range(i):
if list1[x] not in list2:
list2.append(list1[x])
print(list2)