I want to write a nice one line list comprehension with "extend functionality", that also includes a conditional. here is what I have that works
nouns = []
[nouns.extend(value)/ for key, value in pos_dictionary.iteritems()
if key.startswith('NN') ]
ideally I write something nice like
nouns = [nouns.extend(value) for key, value in pos_dictionary.iteritems()
if key.startswith('NN') ]
Which doesn't work because I haven't defined the list yet. The former isn't super horrible, essentially using the comprehension as functional List.iter statement. While I am new to python, this still doesn't seem like the correct style. If this is the proper style, I would appreciate some verification.
I am encountering this sceneario because I am looking to aggregate all the different types of Nouns Tags from the POS tagger (using NLTK) into a single list.
Edit: I agree it is nearly a duplicate, i didn't think if this as flattening a list, but now that it has been introduced as a possibility i can accept it. The one variant is that my example did include a conditional in the comprehension. Also I was inquiring as to the preferred idiomatic syntax, which while possibly open ended is a nice bit for a newbie to python.