Re: [Tutor] python lists/nested lists

2013-04-13 Thread Steven D'Aprano
On 14/04/13 06:53, Soliman, Yasmin wrote: How can I calculate the average of a list of numbers (eg [2,5,8,7,3] ) and then subtract the avg from the original numbers in the list and print? You calculate the average by summing the list, then dividing by the number of items. To sum a list of n

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-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 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] Chapter 3 Projects

2013-04-13 Thread Mariel Jane Sanchez
Thank you for the help, it was really convenient.  From: ALAN GAULD To: Mariel Jane Sanchez Cc: "tutor@python.org" Sent: Tuesday, April 9, 2013 6:29:57 PM Subject: Re: [Tutor] Chapter 3 Projects Forwarded to group. Please use ReplyAll when responding to

Re: [Tutor] python lists/nested lists

2013-04-13 Thread Alan Gauld
On 13/04/13 21:53, Soliman, Yasmin wrote: How can I calculate the average of a list of numbers (eg [2,5,8,7,3] ) > and then subtract the avg from the original numbers > in the list and print? This sounds like homework which we don;t do for you. However to calculate the average take the sum and

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] python lists/nested lists

2013-04-13 Thread Mark Lawrence
On 13/04/2013 21:53, Soliman, Yasmin wrote: How can I calculate the average of a list of numbers (eg [2,5,8,7,3] ) and then subtract the avg from the original numbers in the list and print? lst = [2,5,8,7,3] avg = sum(lst) / len(lst) print(avg) for n in lst: print(n - avg) Also, if I ha

[Tutor] python lists/nested lists

2013-04-13 Thread Soliman, Yasmin
How can I calculate the average of a list of numbers (eg [2,5,8,7,3] ) and then subtract the avg from the original numbers in the list and print? Also, if I have a nested list: sick_patients=[['Sam', 'M', 65, 'chest pain', 101.6], [['Sarah', 'F', 73, 'dizziness', 98.6], [['Susie', 'F', 34, 'he

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 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 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 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 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 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: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
> > 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 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 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 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] design question (Django?)

2013-04-13 Thread Alan Gauld
On 13/04/13 09:48, Albert-Jan Roskam wrote: I think I have to make a diagram of this. This stuff is quite hard You could use a simple UML class diagram (class -> table). See the OOP topic in my V3 tutorial for simple examples. Or you could use a proper entity relationship diagram(ERD) - see

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] design question (Django?)

2013-04-13 Thread Albert-Jan Roskam
Hi Alan, Thanks for your reply! > Subject: Re: [Tutor] design question (Django?) > > Some clarification please. > >> (1) Database design. Here are the database tables I think are necessary: >> tblPostalcode: pc6, streetname, nHouseholds, isVisitable, remarks >> tblCollectorSelection: colle

Re: [Tutor] design question (Django?)

2013-04-13 Thread Alan Gauld
Some clarification please. (1) Database design. Here are the database tables I think are necessary: tblPostalcode: pc6, streetname, nHouseholds, isVisitable, remarks tblCollectorSelection: collectorname, streetname, selectiondate streetname is in both so presumably is the link between collecto

[Tutor] design question (Django?)

2013-04-13 Thread Albert-Jan Roskam
Hi, I am doing volunteer work for a charity. The job is to coordinate money collecting activities of people who raise money with collecting-boxes. I am involved with one postal code  4 (pc4) area (our postal codes have the format 1234 AB (postal code 6). So 'one postal code 4 area'  means [0-9]