[Tutor] How can I extract a specific sublist from a nested list?

prasanna srivatsav.prasanna at gmail.com
Wed Mar 11 08:51:50 CET 2009


Just a suggestion:

It would be better if you turn this list into a dictionary. I presume
you want to know the "adjective" or "noun" of the sentence. To do
that, it would be easier if you had a dictionary.

You can do this as:
>> dict(nested_sublist[1])
{'ADJ': 'good', 'DET': 'The', 'NOUN': 'man'}



2009/3/11 Lie Ryan <lie.1296 at gmail.com>:
> Emad Nawfal (عماد نوفل) wrote:
>>
>> Hi Tutors,
>> How can I extract a specific sublist (??) from a nested list, for example,
>
> The same as the way you extract other objects from non-nested list
>
>> if I want to extract the sublist ["ADJ", "good"],
>
> nested_list[1][2]
>
>> or the bigger sublist  ["NP",["DET", "The"],["ADJ", "good"],["NOUN",
>> "man"]]
>
> nested_list[1]
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Prasanna.,


More information about the Tutor mailing list