How to remove brackets from lists in list using list comprehension?

Question:

I’d like to remove the brackets around my querysets using list comprehension.

This is what I have :

foo = [[<queryset: two>], [<queryset: four>], [<queryset: one>]] 

And this is what I want :

bar = [<queryset: two>, <queryset: four>, <queryset: one>] 

I tried to use list comprehension like so but it didn’t change anything :

bar = [x for x in foo]

What am I doing wrong ?

Asked By: Hiroyuki Nuri

||

Answers:

Try this,

In [1]: foo = [['<queryset: two>'], ['<queryset: four>'], ['<queryset: one>']]
In [2]: [i[0] for i in foo]
Out[2]: ['<queryset: two>', '<queryset: four>', '<queryset: one>']
Answered By: Rahul K P
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.