Issue
I have a nested array in a nested array that is within ANOTHER nested array, i'm trying to move the baby nested array one position behind the second nested array.
So, for example ['ZOMB',15]
one position behind replacing the None, and the None will replace the zomb, and I'm trying to do this for all rows applicable
field = [ [['PEASH', 5], None, None, None, None, None, ['ZOMB', 15]],
[['PEASH', 5], None, None, None, None, None, ['ZOMB', 15]],
[None, None, None, None, None, None, None],
[None, None, None, None, None, None, None],
[None, None, None, None, None, None, None] ]
Solution
You can try inserting ['ZOMB', 15] into index you want to swap with below;
field[0].insert(5, field[0].pop(6))
Output;
[[['PEASH', 5], None, None, None, None, ['ZOMB', 15], None], [['PEASH', 5], None, None, None, None, None, ['ZOMB', 15]], [None, None, None, None, None, None, None], [None, None, None, None, None, None, None], [None, None, None, None, None, None, None]]
So basically you can tailor below method for your need
My_List.insert(index_to_insert,My_List.pop(index_to_remove))
Answered By - Lanre
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.