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
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
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
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
"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
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(
"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
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
"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
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
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
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
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:
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
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
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
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
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(
18 matches
Mail list logo