I have list
players = [[['QB1',7000,20],['RB1',4500,12],['RB2',3800,11]],
[['QB1',7000,20],['RB2',3800,11],['RB1',4500,12]]]
How do I get the first element of each inner-most lists ('QB1', 'RB1' and 'RB2' from the first "secondary," if you will, list) to check if they are the same, however disordered labels as those in another secondary list (they are in this case as both secondary lists contain 'QB1', 'RB1' and 'RB2')?
EDIT:
My desired out is [['QB1','RB1','RB2'],['QB1','RB2','RB1']]
. I want to have some way of identifying that these are, for my purpose, the same list.
You can do this:
output = [[i[0] for i in a] for a in players]
The output
will be like this:
[['QB1', 'RB1', 'RB2'], ['QB1', 'RB2', 'RB1']]
you can use recursive search for that and get first element of each list or whole list
players = [[['QB1',7000,20],['RB1',4500,12],['RB2',3800,11]],[['QB1',7000,20],['RB2',3800,11],['RB1',4500,12]]]
def retrive_first(lst):
for item in lst:
if type(item) == list:
retrive_first(item)
else:
print "returning ---> ", lst[0]
return lst[0]
print retrive_first(players)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With