On Fri, 2011-04-15 at 12:34 +1000, Ryan Kelly wrote:
> On Fri, 2011-04-15 at 12:10 +1000, Chris Angelico wrote:
> >
> > 
> > My first draft looks something like this. The input dictionary is
> > called dct, the output list is lst.
> > 
> > lst=[]
> > for i in xrange(1,10000000): # arbitrary top, don't like this
> >   try:
> >     lst.append(parse_kwdlist(dct["Keyword%d"%i]))
> >   except KeyError:
> >     break
> >
> It might be even easier to just iterate through the dictionary keys:
> 
>   for k in sorted(dct.keys()):
>       if k.startswith("Keyword"):
>           lst.append(parse_kwdlist(dct[k]))

Actually sorted() won't work here, since it sorts lexicographically.  So
you'd wind up with "Keyword111" before "Keyword2".  You would have to
sort after extracting the necessary info (assuming order is actually
important in the final list)


   Ryan


-- 
Ryan Kelly
http://www.rfk.id.au  |  This message is digitally signed. Please visit
r...@rfk.id.au        |  http://www.rfk.id.au/ramblings/gpg/ for details

Attachment: signature.asc
Description: This is a digitally signed message part

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to