hi all,
im new to python, and i have a problem that needs to be solved.

i have the following set:
[[5,5,5],[5,5,5,5,5],[]]

which needs to end up being:
[[5,5,5,5],[],[5,5,5,5]]

has anyone got any suggestions?

Recommended Answers

All 2 Replies

If you want to move an item that's already in the list to the specified position, you would have to delete it and insert it at the new position.
l.insert(newindex, l.pop(oldindex))

>>> l = [[5,5,5],[5,5,5,5,5],[]]
>>> l.insert(1, l.pop(2))
>>> l
[[5, 5, 5], [], [5, 5, 5, 5, 5]]
>>>

snippsat's answer doesn't seem to relate to the 'search' part of your title... and doesn't actually do what you said needed to happen. Can you be a little more complete about the requirements? What is the description of what needs to happen? For instance this description of the task would give the result you wanted: Merge all sub-lists, then place the first half (rounded up) of the elements as a list at index 0 of the outer list, followed by an empty list, followed by a list of the remainder of the merged elements.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.