looping through values in a dictionary and appending to a list

Andre Engels andreengels at gmail.com
Wed Aug 12 10:54:05 CEST 2009

On Tue, Aug 11, 2009 at 8:17 PM, Krishna
Pacifici<pacificik at warnell.uga.edu> wrote:
> Nevermind,
> got it.
> Sorry.
>>>> Krishna Pacifici 08/11/09 2:12 PM >>>
> Hi,
> I want to append the values of a dictionary to a list.  I have a dictionary
> sec_dict_clean and I want to append the values to a list, but am having a
> hard time looping through the values in the dictionary.
> I have tried something like this:
> lista=[]
> for i in sec_dict_clean.values():
>     for j in sec_dict_clean.values()[i]:
>         lista.append(sec_dict_clean.values()[i])
> But I keep on getting an error:
> TypeError: list indices must be integers
> Any ideas on how to loop through values in a dictionary?

for value in sec_dict_clean.values():

but even simpler would be:

lista = sec_dict_clean.values()

André Engels, andreengels at gmail.com

More information about the Python-list mailing list