[Tutor] creating dictionary from a list

Steven D'Aprano steve at pearwood.info
Sun Apr 14 03:57:21 CEST 2013


On 14/04/13 05:30, Saad Bin Javed wrote:
> This is what I'm using:
>
> for item in lst:
>      if item.startswith(('Mon','Tue','____Wed','Thu','Fri','Sat','Sun'__))__:
>          dict[item] = []
>          saveItem = item
>      else:
>          dict[saveItem].append(item.____strip())
>
> gives:
>   File "gcalcli_agenda_test.py", line 39
>      if item.startswith(('Mon','Tue','____Wed','Thu','Fri','Sat','Sun'__))__:
>                                                                        ^
> SyntaxError: invalid syntax


Notice the little caret ^ on the line above "SyntaxError"? It points to where
Python discovers a problem with the syntax of your code.

The underscores do not belong there. They were added by your email program. Why,
I have no idea. Take them out. Likewise with the following underscores.

And with the '____Wed' string. This should be your first hint that something is
wrong. The days of the week start Mon, Tue, Wed, not Mon, Tue, ____Wed.


(I have no idea what your email program will do with these underscores. If in
doubt, your mail client should give you a way to look at the raw, untouched message
source. In Thunderbird, I can go to the View menu and select "Message Source", and
that will show the complete email, including all headers and raw attachments. That
at least ought to show you the text without any mangling. Hopefully.)




-- 
Steven


More information about the Tutor mailing list