the first element in the list of list

B

Ben Bush

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]]
 
B

bruno at modulix

Ben said:
I have a lis:
[[1,3],[3,4],[5,6],[8,9],[14,0],[15,8]]
I want a code

Then write it.

And when (if) you have problems with it, repost, we'll then be happy to
help you.
to test when the difference between the first element in
the list of list is equal to or larger than 6,

I'm afraid you will never know what that difference is... Reminds me of
zen koan saying "the difference between a bird is that it neither know
how to fly".

Note that the use of "between" usually implies a second term !-)

BTW, also note that "the first element the first element in (a) list of
list(s)" is usually (well, I'd even say "always") a list itself.
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]]
 
D

Dennis Benzinger

Ben said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,270
Messages
2,571,353
Members
48,038
Latest member
HunterDela

Latest Threads

Top