I have a list like below where the first element is the id and the other is a string:
JavaScript
x
2
1
[(1, u'abc'), (2, u'def')]
2
I want to create a list of ids only from this list of tuples as below:
JavaScript
1
2
1
[1,2]
2
I’ll use this list in __in
so it needs to be a list of integer values.
Advertisement
Answer
JavaScript
1
4
1
>>> a = [(1, u'abc'), (2, u'def')]
2
>>> [i[0] for i in a]
3
[1, 2]
4