Re: [Tutor] working with multiple sets

2009-09-09 Thread Kent Johnson
On Wed, Sep 9, 2009 at 7:48 AM, kevin parks wrote: > Then i can cast it as a dict and pick over that dictionary as i wish. There is no need for that. defaultdict is a subclass of dict and supports all the methods of dict. > Here > (as a bonus) I can transverse a range of keys that is inclusive

Re: [Tutor] working with multiple sets

2009-09-09 Thread kevin parks
Are any of these methods better than another for some reason? On Sep 9, 2009, at 10:12 PM, Lie Ryan wrote: kevin parks wrote: This discussion is making my brain melt. It is also showing how clever Bob was to do it the way he did... I found a solution that i think works, and think has not ye

Re: [Tutor] working with multiple sets

2009-09-09 Thread Lie Ryan
kevin parks wrote: This discussion is making my brain melt. It is also showing how clever Bob was to do it the way he did... I found a solution that i think works, and think has not yet been suggested. I quarantined Bob's code into a black box ... and then cast the output as a plain old fashi

Re: [Tutor] working with multiple sets

2009-09-09 Thread kevin parks
This discussion is making my brain melt. It is also showing how clever Bob was to do it the way he did... I found a solution that i think works, and think has not yet been suggested. I quarantined Bob's code into a black box ... and then cast the output as a plain old fashioned python built

Re: [Tutor] working with multiple sets

2009-09-08 Thread Alan Gauld
"Lie Ryan" wrote for key, value in sets.items(): for element in value: try: lookup[element] = lookup[element].append(key) This has the same flaw as mine. it nneeds to be lookup[element].append(key) ie no assignment, othewise

Re: [Tutor] working with multiple sets

2009-09-08 Thread Lie Ryan
Alan Gauld wrote: "kevin parks" wrote What would this look like if i want to use a straight up built-in dictionary type and not the collections.defaultdict. Not too different: Alternatively: import collections def foo(): lookup = collections.defaultdict(list) x = range(10) y = range(

Re: [Tutor] working with multiple sets

2009-09-08 Thread Alan Gauld
"Douglas Philips" wrote for element in value: lookup[element] = lookup.get(element, []).append(key) # Doug: That doesn't do what you think it does, it won't insert the new list into the dictionary. Ah, yes I forgot append was one of those annoying python methods t

Re: [Tutor] working with multiple sets

2009-09-08 Thread Douglas Philips
On or about 2009 Sep 8, at 1:51 PM, Alan Gauld indited: "kevin parks" wrote What would this look like if i want to use a straight up built-in dictionary type and not the collections.defaultdict. Not too different: import collections def foo(): lookup = collections.defaultdict(list) # Dou

Re: [Tutor] working with multiple sets

2009-09-08 Thread Alan Gauld
"kevin parks" wrote What would this look like if i want to use a straight up built-in dictionary type and not the collections.defaultdict. Not too different: import collections def foo(): lookup = collections.defaultdict(list) x = range(10) y = range(5, 15) z = range(8, 22) sets = {'x

Re: [Tutor] working with multiple sets

2009-09-08 Thread kevin parks
I guess what i honestly want to asks, but am hesitant to since it makes me look like a dork is: What would this look like if i want to use a straight up built-in dictionary type and not the collections.defaultdict. import collections def foo(): lookup = collections.defaultdict(l

Re: [Tutor] working with multiple sets

2009-09-08 Thread kevin parks
Actually, This seems like it works: lookup[x].sort() in like so: def foo(): lookup = collections.defaultdict(list) x = range(10) y = range(5, 15) z = range(8, 22) sets = {'x': set(x), 'y': set(y), 'z': set(z)} for key, value in s

Re: [Tutor] working with multiple sets

2009-09-08 Thread Kent Johnson
On Tue, Sep 8, 2009 at 10:07 AM, kevin parks wrote: > I also notice that if i do: > > > def foo(): >        lookup = collections.defaultdict(list) >        x = range(10) >        y = range(5, 15) >        z = range(8, 22) >        sets = {'x': set(x), 'y': set(y), 'z': set(z)} >        for key, val

Re: [Tutor] working with multiple sets

2009-09-08 Thread kevin parks
I also notice that if i do: def foo(): lookup = collections.defaultdict(list) x = range(10) y = range(5, 15) z = range(8, 22) sets = {'x': set(x), 'y': set(y), 'z': set(z)} for key, value in sets.items(): for element in value:

Re: [Tutor] working with multiple sets

2009-09-08 Thread bob gailer
kevin parks wrote: I am looking at this and wondering: Why does this use collections.defaultdict ? In fact i guess since collections.defaultdict is new to me i am not even sure why it exists and why someone would use this as opposed to using Python's built-in dictionary? and why was it use

Re: [Tutor] working with multiple sets

2009-09-08 Thread kevin parks
I am looking at this and wondering: Why does this use collections.defaultdict ? In fact i guess since collections.defaultdict is new to me i am not even sure why it exists and why someone would use this as opposed to using Python's built-in dictionary? and why was it used in this instance

[Tutor] working with multiple sets

2009-09-05 Thread bob gailer
1) Please don't hijack a post then change the subject. That screws things up for email clients that track threads. I have started a new thread with this reply. 2) Be sure to reply-all so a copy goes to the list. [SNIP] I want to be able to look at a number/item and see which lists it is in s

Re: [Tutor] working with multiple sets

2009-09-05 Thread Dave Angel
kevin parks wrote: I am doing some simple things with sets and so far have had a lot of success with python's built-in sets, which is such a great new(ish) "batteries included" type python data type. [snip] [snip] -- [snip] [snip] -- #!/usr/bin/env

[Tutor] working with multiple sets

2009-09-05 Thread kevin parks
I am doing some simple things with sets and so far have had a lot of success with python's built-in sets, which is such a great new(ish) "batteries included" type python data type. [snip] [snip] -- [snip] [snip] -- #!/usr/bin/env python def test(