0

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?

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by griswolf
0

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

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.