[Tutor] creating dictionary from a list

2013-04-12 Thread Saad Bin Javed
Hi, I'm using a script to fetch my calendar events. I split the output at newline which produced a list 'lst'. I'm trying to clean it up and create a dictionary with date:event key value pairs. However this is throwing up a bunch of errors. lst = ['', 'Thu Apr 04 Weigh In', '', 'Sat

Re: [Tutor] creating dictionary from a list

2013-04-12 Thread Steven D'Aprano
On 13/04/13 09:52, Saad Bin Javed wrote: Hi, I'm using a script to fetch my calendar events. I split the output at newline which produced a list 'lst'. I'm trying to clean it up and create a dictionary with date:event key value pairs. However this is throwing up a bunch of errors. Would you

Re: [Tutor] creating dictionary from a list

2013-04-12 Thread Saad Bin Javed
Thank you Steven! I followed your tips and came up with this: lst = filter(None, lst) lst = [item.split(' ', 1) for item in lst] lst = [item for sublist in lst for item in sublist] lst = filter(None, lst) dict = {} for item in lst: if item.startswith(('Mon','Tue','Wed','Thu','Fri','Sat'

Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Brian van den Broek
On 12 Apr 2013 21:25, "Steven D'Aprano" wrote: > Also, you might find it easier to process the list if you strip out empty items. There are two simple ways to do it: > > > lst = [x for x in list if x != ''] > # or > lst = filter(None, lst) Hi all, For the first, I would use lst = [x for x in l

Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Saad Bin Javed
I ran into a bit of problem with my revised code based on Steven's suggestions. lst = ['', 'Thu Apr 04 Weigh In', '', 'Sat Apr 06 Collect NIC', ' Finish PTI Video', '', 'Wed Apr 10 Serum uric acid test', '', 'Sat Apr 13 1:00pm Get flag from dhariwal', '', 'Su

Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Mark Lawrence
On 13/04/2013 15:34, Saad Bin Javed wrote: I ran into a bit of problem with my revised code based on Steven's suggestions. lst = ['', 'Thu Apr 04 Weigh In', '', 'Sat Apr 06 Collect NIC', ' Finish PTI Video', '', 'Wed Apr 10 Serum uric acid test', '', 'Sat Apr 13

Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Saad Javed
What just happened here? :) I am trying to learn python so i'm sorry if my mistakes seem trivial. On Saturday, April 13, 2013, Mark Lawrence wrote: > On 13/04/2013 15:34, Saad Bin Javed wrote: > >> I ran into a bit of problem with my revised code based on Steven's >> suggestions. >> >> lst = [''

Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Saad Javed
> > Don't fight Python, unlike this chap[1] :) Basically if you're looping > around any data structure you rarely need to use indexing, so try this > approach. > > for item in lst: > if item.startswith(('Mon','Tue','**Wed','Thu','Fri','Sat','Sun'))**: > myDict[item] = [] > save

Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Mark Lawrence
On 13/04/2013 19:19, Saad Javed wrote: Don't fight Python, unlike this chap[1] :) Basically if you're looping around any data structure you rarely need to use indexing, so try this approach. for item in lst: if item.startswith(('Mon','Tue','__Wed','Thu','Fri','Sat

Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Saad Javed
> for item in lst: >> if >> item.startswith(('Mon','Tue','**__Wed','Thu','Fri','Sat','Sun'**))__: >> myDict[item] = [] >> saveItem = item >> else: >> myDict[saveItem].append(item._**_strip()) >> >> Returns: File "gcalcli_agenda_test.

Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Mark Lawrence
On 13/04/2013 19:45, Saad Javed wrote: for item in lst: if item.startswith(('Mon','Tue','Wed','Thu','Fri','Sat','Sun'__))__: myDict[item] = [] saveItem = item else: myD

Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Saad Bin Javed
On 04/14/2013 12:08 AM, Mark Lawrence wrote: On 13/04/2013 19:45, Saad Javed wrote: for item in lst: if item.startswith(('Mon','Tue','Wed','Thu','Fri','Sat','Sun'__))__: myDict[item] = [] saveItem = item

Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Mark Lawrence
On 13/04/2013 20:30, Saad Bin Javed wrote: On 04/14/2013 12:08 AM, Mark Lawrence wrote: On 13/04/2013 19:45, Saad Javed wrote: for item in lst: if item.startswith(('Mon','Tue','Wed','Thu','Fri','Sat','Sun'__))__: myDict[item] = []

Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Saad Javed
I don't know what I'm doing wrong here. Ive tried copy-pasting the line. I've tried entering underscores manually. doesn't work. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo

Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Mark Lawrence
On 13/04/2013 21:06, Saad Javed wrote: I don't know what I'm doing wrong here. Ive tried copy-pasting the line. I've tried entering underscores manually. doesn't work. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription optio

Re: [Tutor] creating dictionary from a list

2013-04-13 Thread eryksun
On Fri, Apr 12, 2013 at 7:52 PM, Saad Bin Javed wrote: > Hi, I'm using a script to fetch my calendar events. I split the output at > newline which produced a list 'lst'. I'm trying to clean it up and create a > dictionary with date:event key value pairs. However this is throwing up a > bunch of er

Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Steven D'Aprano
On 14/04/13 03:38, Saad Javed wrote: What just happened here? :) I am trying to learn python so i'm sorry if my mistakes seem trivial. I have to ask the same question -- what just happened here? Why are you upset? Mark has given you some good advice, and even added some light-hearted joviali

Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Steven D'Aprano
On 14/04/13 04:19, Saad Javed wrote: This creates a dictionary whose keys are out of order in terms of dates. Dictionaries are unordered. That is to say, they have no defined order, when you print them, or iterate over them, items will appear in whatever order they happen. If you modify a dic

Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Steven D'Aprano
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_ag

Re: [Tutor] creating dictionary from a list

2013-04-14 Thread Saad Javed
Steven, You're right about Mark's email. I didn't get the humor and thought the remark was kinda tough on me. You correctly pointed out his intent. So my apologies to Mark. As for the underscores, what happened is that *I didn't voluntarily add the underscores to begin with. *If you read the emai

Re: [Tutor] creating dictionary from a list

2013-04-14 Thread eryksun
On Sun, Apr 14, 2013 at 12:46 PM, Saad Javed wrote: > > As for the underscores, what happened is that I didn't voluntarily add the > underscores to begin with. If you read the emails again, after Mark's answer > about not looping, I asked that the dictionary created as a result of his > code wasn'

Re: [Tutor] creating dictionary from a list

2013-04-14 Thread Saad Bin Javed
On 04/14/2013 10:50 PM, eryksun wrote: I don't know how the underline tags got in there. They aren't in the quote in Mark's message. Either way, for the plain text part, your email program substituted "**". Others substituted "__". There'd be no problem if you didn't use rich text in the first

Re: [Tutor] creating dictionary from a list

2013-04-15 Thread Saad Bin Javed
On 04/15/2013 01:42 PM, Sydney Shall wrote: Dear Saad, Could you please tell me how to change the Thunderbird settings to plain text. I could not find the correct menu. Many thanks, Sydney Go to Preferences > Composition > Send Options and add python.org under Plain Text Domains. ___