Can I unpack a list of numbers into a list of indexes? For example, I have lists in a list containing these numbers:
a = [[25,26,1,2,23], [15,16,11,12,10]]
I need to place them in a template, so I did something like this
newA = []
for lst in a:
new_nums = [lst[4],lst[2],lst[3],lst[0],lst[1]]
newA.append(new_nums)
print (newA)
so instead of writing, new_nums = [lst[4],lst[2],lst[3],lst[0],lst[1]]I thought about defining a template as a list with a name pattern = [4,2,3,0,1], and then unpacking them into those indexes lstto create a new order lst.
Is there a great way to do this.
source
share