Stop sending your mails Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > [EMAIL PROTECTED] > > You can reach the person managing the list at > [EMAIL PROTECTED] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > > Today's Topics: > > 1. Re: creating a nested dictionary (Remco Gerlich) > 2. Re: Comparing more than 2 lists (Fiyawerx) > 3. lst file (SwartMumba snake) > 4. Re: lst file (Remco Gerlich) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Thu, 24 Jan 2008 10:51:39 +0100 > From: "Remco Gerlich" <[EMAIL PROTECTED]> > Subject: Re: [Tutor] creating a nested dictionary > To: "Garry Willgoose" <[EMAIL PROTECTED]> > Cc: tutor@python.org > Message-ID: > <[EMAIL PROTECTED]> > Content-Type: text/plain; charset="utf-8" > > Of course, I forgot to mention that you can use tuples as dictionary keys. > > A common idiom is: > > pdb[(dataset, modulename, parametername, 'value')] = value. > > And if that works for you, it's much simpler. But you lose the ability to > use, say, pdb[dataset][modulename] as a dictionary on its own. > > Remco > > > On Jan 24, 2008 8:20 AM, Garry Willgoose > <[EMAIL PROTECTED]> > wrote: > >> Is there any easy way to create a nested dictionary. I want to be >> able to allocate like >> >> pdb[dataset][modulename][parametername]['value']=value >> >> where dataset, modulename, parametername are variables that are >> determined within loops nested 3 deep, and value comes from a >> database call. Prior to the nested loops I do not know what the >> values of dataset, modulename, parametername will range over, but I >> do know pdb needs to be nested 3 deep. What I'd like to do is >> something like this >> >> pdb={} >> for dataset in dataset_list: >> modulename_list=getmodules(dataset) >> for modulename in modulename_list: >> parametername_list=getparameters(dataset,modulename) >> for parametername in parametername_list: >> value=getvalue(dataset, modulename, >> parametername) >> >> pdb[dataset][modulename][parametername]['value']=value >> >> What I'm currently doing is >> >> pdb={} >> for dataset in dataset_list: >> modulename_list=getmodules(dataset) >> moduledict={} >> for modulename in modulename_list: >> parametername_list=getparameters(dataset,modulename) >> valuedict={} >> for parametername in parametername_list: >> value=getvalue(dataset, modulename, >> parametername) >> valuedict['value']=value >> # valuedict needs to be a dictionary because there is other stuff >> valuedict['otherstuff]=otherstuff >> ... >> parameterdict[parametername]=valuedict.copy() >> moduledict[modeulename]=copy.deepcopy(parameterdict) >> pdb[dataset]=copy.deepcopy(moduledict) >> >> >> Now I know the 2nd is not that much more complex but this is a pretty >> common construct in what I'm doing so I'm just wondering if there is >> a clear and simple shortcut ;-) >> >> >> ==================================================================== >> Prof Garry Willgoose, >> Australian Professorial Fellow in Environmental Engineering, >> Director, Centre for Climate Impact Management (C2IM), >> School of Engineering, The University of Newcastle, >> Callaghan, 2308 >> Australia. >> >> Centre webpage: www.c2im.org.au >> >> Phone: (International) +61 2 4921 6050 (Tues-Fri AM); +61 2 6545 9574 >> (Fri PM-Mon) >> FAX: (International) +61 2 4921 6991 (Uni); +61 2 6545 9574 (personal >> and Telluric) >> Env. Engg. Secretary: (International) +61 2 4921 6042 >> >> email: [EMAIL PROTECTED]; >> [EMAIL PROTECTED] >> email-for-life: [EMAIL PROTECTED] >> personal webpage: www.telluricresearch.com/garry >> ==================================================================== >> "Do not go where the path may lead, go instead where there is no path >> and leave a trail" >> Ralph Waldo Emerson >> ==================================================================== >> >> >> >> >> >> _______________________________________________ >> Tutor maillist - Tutor@python.org >> http://mail.python.org/mailman/listinfo/tutor >> > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > http://mail.python.org/pipermail/tutor/attachments/20080124/483b019b/attachment-0001.htm > > ------------------------------ > > Message: 2 > Date: Thu, 24 Jan 2008 05:37:46 -0500 > From: Fiyawerx <[EMAIL PROTECTED]> > Subject: Re: [Tutor] Comparing more than 2 lists > To: "Michael Langford" <[EMAIL PROTECTED]>, tutor@python.org > Message-ID: > <[EMAIL PROTECTED]> > Content-Type: text/plain; charset="iso-8859-1" > > Thanks Michael, this worked great, time to read up on collections! > > On Jan 24, 2008 3:36 AM, Michael Langford <[EMAIL PROTECTED]> > wrote: > >> You use a variation on bucket sort do to this: >> http://en.wikipedia.org/wiki/Bucket_sort >> >> You make a dict where the keys are the values in the lists, and a name >> for each list is in the problem. >> >> So you get something that looks like: >> >> one: list1, list2 >> two: list1, list2, list3 >> etc >> >> Doing this with collections.defaultdict is a breeze: >> import collections >> >> dd = collections.defaultdict(list) >> for eachlist in lists: >> for each in eachlist: >> dd[each].append(getListName(eachlist)) >> >> Then to find the repeated elements you filter where the list is of >> length >> > 1. >> >> for each in dd: >> print "%s: %s" % (each, dd[each]) >> >> I'd provide code, but I'm not sure what an appropriate naming function >> is for you, nor am I sure what you're doing with this when you're >> done. >> >> --Michael >> >> >> >> On Jan 24, 2008 3:15 AM, Fiyawerx <[EMAIL PROTECTED]> wrote: >> > I have been able to find a few articles on comparing 2 lists, but I >> have >> 4 >> > lists that I need to compare. I need to find any repeated elements and >> the >> > list that they came from. For example, >> > >> > list1 = ['one', 'two', 'three'] >> > list2 = ['one', 'two', 'four', 'five'] >> > list3 = ['two', 'three', 'six', 'seven'] >> > list4 = ['three', 'five', 'six'] >> > https://mail.google.com/mail/#label/Pythontutor/117aadf8364dbf3b >> Gmail - [Tutor] Comparing more than 2 lists - [EMAIL PROTECTED] >> > >> > I need to be able to get along the lines of output: >> > Element 'one' contained in list1 and list2 >> > Element 'two' contained in list1 and list2 and list3 >> > ... >> > Element 'five' contained in list2 and list4 >> > >> > etc.. and I can't quite figure out how to go about it >> > >> > >> > _______________________________________________ >> > Tutor maillist - Tutor@python.org >> > http://mail.python.org/mailman/listinfo/tutor >> > >> > >> >> >> >> -- >> Michael Langford >> Phone: 404-386-0495 >> Consulting: http://www.RowdyLabs.com >> > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > http://mail.python.org/pipermail/tutor/attachments/20080124/feca40e7/attachment-0001.htm > > ------------------------------ > > Message: 3 > Date: Thu, 24 Jan 2008 02:42:59 -0800 (PST) > From: SwartMumba snake <[EMAIL PROTECTED]> > Subject: [Tutor] lst file > To: tutor@python.org > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset="iso-8859-1" > > Hi > > I am trying to read from a specific .lst file. When I read from it, it > just prints out blank lines and I am sure that this file contains content. > > This is what I am using to read from the file: > > f = open("C:\\Users\\UserName\\Directory\\words.lst") > > for line in f: > print line > > f.close() > > Do you guys know what is wrong? > > Thanks in advance. > > > --------------------------------- > Never miss a thing. Make Yahoo your homepage. > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > http://mail.python.org/pipermail/tutor/attachments/20080124/017ddbdc/attachment-0001.htm > > ------------------------------ > > Message: 4 > Date: Thu, 24 Jan 2008 11:54:04 +0100 > From: "Remco Gerlich" <[EMAIL PROTECTED]> > Subject: Re: [Tutor] lst file > To: "SwartMumba snake" <[EMAIL PROTECTED]> > Cc: tutor@python.org > Message-ID: > <[EMAIL PROTECTED]> > Content-Type: text/plain; charset="utf-8" > > Many things could be wrong; perhaps with reading the file, or the lines, > or > with printing them... Debugging usually consists of what the problem is > exactly, where it occurs. > > First thing I'd look at is seeing whether the lines do get read. I would > change "print line" into "print len(line)" and see if the lines are empty, > or filled with unprintable things. > > Also, what sort of file is it? > > Remco > > > On Jan 24, 2008 11:42 AM, SwartMumba snake <[EMAIL PROTECTED]> wrote: > >> Hi >> >> I am trying to read from a specific .lst file. When I read from it, it >> just prints out blank lines and I am sure that this file contains >> content. >> >> This is what I am using to read from the file: >> >> f = open("C:\\Users\\UserName\\Directory\\words.lst") >> >> for line in f: >> print line >> >> f.close() >> >> Do you guys know what is wrong? >> >> Thanks in advance. >> >> ------------------------------ >> Never miss a thing. Make Yahoo your >> homepage.<http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs> >> >> _______________________________________________ >> Tutor maillist - Tutor@python.org >> http://mail.python.org/mailman/listinfo/tutor >> >> > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > http://mail.python.org/pipermail/tutor/attachments/20080124/7d98c7ec/attachment-0001.htm > > ------------------------------ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > End of Tutor Digest, Vol 47, Issue 64 > ************************************* >
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor