I know I'm gonna feel dumb in the Morning....

Peter Hansen peter at engcorp.com
Thu May 22 21:28:04 EDT 2003


"yaipa h." wrote:
> 
> What I really want to do is,
> 
>     for f in _fromDict.keys().sort():
> 
> But that fails, so then I try this...
> 
> >>> ==================== Code Snippet ===========================
>       fLst = []
>       fLst = _fromDict.keys().sort()
> 
>    # Now convert each From Object against the entire list of fromObjects
>    for f in fLst:
> 
> >>> ==================== PROGRAM START ===========================
> 
> Traceback (most recent call last):
>   File "C:\jDev\cs-171\project\cs171\ctt.py", line 124, in -toplevel-
>     for f in fLst:
> TypeError: iteration over non-sequence
> 
> Now I've made 'fLst' a list explicitly. Sooooo why doesn't this work?

It will help if you learn to use the interactive prompt to 
troubleshoot problems like this.  In this case, after you 
typed the above few lines, you could ask Python to just show
you what fLst contains, and you'd quickly realize that it is
*not* in fact a list, as you believe, after the sort.  Shortly
after that you'd discover that sort() returns None...

-Peter




More information about the Python-list mailing list