Why does one work, but not the other?

Terry Reedy tjreedy at udel.edu
Fri Jun 18 14:59:49 EDT 2004


"j_mckitrick" <j_mckitrick at bigfoot.com> wrote in message
news:ec6dce8b.0406171754.5d5d84db at posting.google.com...
> I've done this before:
>
>         data = [self.cong.tm[k] for k in self.cong.tm.li]
> #li is list, tm is dict
>
> instead of:
>
>          for k in self.cong.tm.li:
>              data.append(self.cong.tm[k])
>
> but when I try:
>
>         self.liststore = [[item] for item in data]
>
>
> instead of:
>
>        for item in data:
>             self.liststore.append([item])
>
> I get an empty list!  What gives??

For questions like this, about supposedly anomalous behavior, you usually
need to give actual input and output, reduced to the minimum code needed to
show the purported behavior.  Otherwise, the easiest guess is that you did
not use the same value of data in the two snippets;-)

Terry J. Reedy







More information about the Python-list mailing list