[Tutor] Counting help
Kent Johnson
kent37 at tds.net
Tue Aug 23 22:06:27 CEST 2005
Scott Oertel wrote:
> The next problem I have though is creating the dict,
>
> i have a loop, but i can't figure out how to compile the dict, it is
> returning this: ('Joey Gale', ('Scott Joe', 'This is lame' )))
>
>
> listofnames = []
> while (cnt < number[1][0]):
> if (date[2] == today[2]):
> test = regex.findall(M.fetch(int(number[1][0]) - cnt,
> '(BODY[HEADER.FIELDS (FROM)])')[1][0][1].rstrip())
> cnt += 1
> if (nameofsender != []):
> print nameofsender[0]
> listofnames = nameofsender[0], listofnames
I think you want
listofnames.append(nameofsender[0])
which will add nameofsender[0] to the list. What you have -
listofnames = nameofsender[0], listofnames
is making a tuple (a pair) out of the new name and the old list, and assigning it to listofnames. Kind of like CONS in LISP - but Python lists are more like arrays than like LISP lists.
Kent
> else:
> no_name += 1
> else: break
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list