473,386 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

the first element in the list of list

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]]
Nov 22 '05 #1
2 1818
Ben Bush wrote:
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]]

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Nov 22 '05 #2
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
Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Randell D. | last post by:
Folks, I know I could do this with a foreach loop but it looks dirty. I'm wondering if I can do this via array_walk() or asort() and would appreciate some help.. I have an array - an example...
2
by: Neal D. Becker | last post by:
What is an efficient way to find the first element in a sequence meeting some condition? For example, the first number > x in a list of numbers.
1
by: Stanimir Stamenkov | last post by:
I've wondered if it is right thing to do: element.parentNode.insertBefore(element, beforeElement); where 'beforeElement' is one of the 'element.parentNode.childNodes'? First, I've used: ...
4
by: eksamor | last post by:
I have a simple linked list: struct element { struct element *next; int start; }; struct list { struct element *head;
3
by: jm.suresh | last post by:
Hi, I have a list and I want to find the first element that meets a condition. I do not want to use 'filter', because I want to come out of the iteration as soon as the first element is found. I...
15
by: caca | last post by:
Hello, This is a question for the best method (in terms of performance only) to choose a random element from a list among those that satisfy a certain property. This is the setting: I need to...
12
by: Phillip B Oldham | last post by:
I'm keen on learning python, with a heavy lean on doing things the "pythonic" way, so threw the following script together in a few hours as a first-attempt in programming python. I'd like the...
0
by: Tim Chase | last post by:
I need to put in the var property of the first object from the list assuming you meant "foo = any.name if ***any*** is not None else beny.name..." If you have a fixed/hard-coded list of...
5
by: goldenteeplanet | last post by:
void reverse( node * & s) { // NOTE: YOU CAN NOT MOVE DATA FROM ONE NODE TO ANOTHER // YOU CAN ONLY MOVE POINTERS FROM ONE NODE TO ANOTHER //...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.