the first element in the list of list

Dennis Benzinger Dennis.Benzinger at gmx.net
Tue Nov 22 10:09:54 EST 2005


Ben Bush schrieb:
> I have a lis:
> [[1,3],[3,4],[5,6],[8,9],[14,0],[15,8]]
> I want a code to test when the difference between the first element in
> the list of list is equal to or larger than 6, then move the previous
> lists to the end of the list. that is:
> [[14,0],[15,8],[1,3],[3,4],[5,6],[8,9]]


your_list = [[1,3],[3,4],[5,6],[8,9],[14,0],[15,8]]


for index, sublist in enumerate(your_list):
     if abs(sublist[1] - sublist[0]) > 6:
         your_list = your_list[index:] + your_list[:index]
         break

print your_list


Bye,
Dennis



More information about the Python-list mailing list