you can use the following: (change the matrices as it suits your app):
import numpy as np
def set_params(w, b):
params = {"w0": w[0], "w1": w[1] , "w2": w[2], "w3": w[3], "w4":
w[4], "b": b}
return params
w = np.random.randn((5))
b = 1
params = set_params(w, b)
for i in range(5)
> So How should I call this:
>
> class ...dict(dict):
> def __init__(self, fun):
> self.fun = fun
>
> def __missing__(self, key):
> return self.fun(key)
I don't know how you should,
but I tried the following
which seems to work
class KeyPlusOne( dict ) :
def __
Op 03-11-14 om 12:09 schreef Chris Angelico:
> On Mon, Nov 3, 2014 at 10:04 PM, Antoon Pardon
> wrote:
>> Is it possible to have a default dictionary where the default is dependant
>> on the key?
>>
>> I was hoping something like this might work:
> m = defaultdict(lambda key: key+1)
>> But it
On Mon, Nov 3, 2014 at 10:04 PM, Antoon Pardon
wrote:
> Is it possible to have a default dictionary where the default is dependant
> on the key?
>
> I was hoping something like this might work:
m = defaultdict(lambda key: key+1)
>
> But it obviously doesn't:
m[3]
>
> Traceback (most rece
Thanks Peter for the fast response, but the prob is solved. My
colleague just verbally slapped me because a dict SHOULDN'T have
duplicate keys...
I change it around to duplicate values and it works fine
I think I need coffee now... lots of it.
--
https://mail.python.org/mailman/listinfo/pyt
In ishish
writes:
> The script [...] only creates batch1.csv.
If the script only creates batch1.csv, that means Batch2 and Batch3 must
be empty.
> for k, v in myDict.items():
> if Batch1.has_key(k):
> if k in Batch2.has_key(k):
> Batch3[k] = v
>
ishish wrote:
> This might sound weird, but is there a limit how many dictionaries a
> can create/use in a single script?
No.
> My reason for asking is I split a 2-column-csv (phone#, ref#) file into
> a dict and am trying to put duplicated phone numbers with different ref
> numbers into new
greatly appreciated guys. thanks!
--
https://mail.python.org/mailman/listinfo/python-list
wrote in message
news:891d3696-4e4e-44cc-a491-6b8fef47f...@googlegroups.com...
> why in a for loop can i access values for a dict that i did not address in
> the for loop.
>
> example:
>
> a = {blah:blah}
> b = {blah:blah}
>
> for x in a:
>
>print a[x]
>
>#here's what i don't understand
On 02/08/2014 11:07 PM, worthingtonclin...@gmail.com wrote:
why in a for loop can i access values for a dict that i did not address in the
for loop.
example:
a = {blah:blah}
b = {blah:blah}
for x in a:
print a[x]
#here's what i don't understand
print b[x]
On 02/18/2013 10:14 PM, Dave Angel wrote:
On 02/18/2013 09:54 PM, Mitya Sirenef wrote:
>> On 02/18/2013 09:17 PM, Jon Reyes wrote:
>>> Thanks Dave and Mitya for enlightening me about dictionaries. I'm
>>> still confused about this though:
>> >
>> > " so that if two
>> > key objects are equal, t
On 02/18/2013 09:54 PM, Mitya Sirenef wrote:
On 02/18/2013 09:17 PM, Jon Reyes wrote:
Thanks Dave and Mitya for enlightening me about dictionaries. I'm
still confused about this though:
>
> " so that if two
> key objects are equal, they stay equal, and if they differ, they stay
> different
On 02/18/2013 09:17 PM, Jon Reyes wrote:
Thanks Dave and Mitya for enlightening me about dictionaries. I'm still
confused about this though:
>
> " so that if two
> key objects are equal, they stay equal, and if they differ, they stay
> different. "
>
> What does this mean? I won't be comparing
Oh, I see, thanks! I was thinking I'll study 2.7 and once I'm comfortable with
Python as a language I'll move to 3. Heck, I don't even know how to create a
simple main method.
--
http://mail.python.org/mailman/listinfo/python-list
On 19/02/2013 01:38, Jon Reyes wrote:
Hi Mark. Well, doesn't iteritems() work the same?
It's iteritems for Python 2, items for Python 3.
--
Cheers.
Mark Lawrence
--
http://mail.python.org/mailman/listinfo/python-list
Thanks Dave and Mitya for enlightening me about dictionaries. I'm still
confused about this though:
" so that if two
key objects are equal, they stay equal, and if they differ, they stay
different. "
What does this mean? I won't be comparing key objects with one another. Also,
when I had two
On 02/18/2013 08:38 PM, Jon Reyes wrote:
Hi Mark. Well, doesn't iteritems() work the same? or am I missing something? By
the way I'm sure I read the dictionaries part of Python but I'm unsure if it
would take int's as a key for dictionaries. I've been weaned on Java where the
keys of hashmaps
On 02/18/2013 08:38 PM, Jon Reyes wrote:
Hi Mark. Well, doesn't iteritems() work the same? or am I missing something? By the way I'm
sure I read the dictionaries part of Python but I'm unsure if it would
take int's as a key for dictionaries. I've been weaned on Java where the
keys of hashmaps
Hi Mark. Well, doesn't iteritems() work the same? or am I missing something? By
the way I'm sure I read the dictionaries part of Python but I'm unsure if it
would take int's as a key for dictionaries. I've been weaned on Java where the
keys of hashmaps are always Strings.
PS: Just checked, wow
On 19/02/2013 00:52, Jon Reyes wrote:
So I have a dictionary and the key is a number. The values are either a single
tuple or a tuple of tuples. Is there a better way to go about accessing the
values of the dictionary? All the tuples contain four elements.
So say:
col = {"1": (0,1,2,3): "2": (
In article ,
Jon Reyes wrote:
> So I have a dictionary and the key is a number.
> [...]
> col = {"1": (0,1,2,3): "2": ((0,1,2,3),(2,3,4,5))}
The keys here are strings, not numbers. But that's a detail. Somewhat
more importantly, that's a syntax error (one of the colons should be a
comma).
Sorry if I didn't check the code before I posted it, I just mocked it up in
Google's editor. That's what Mitya suggested too, yep, I guess I just need to
make it uniform to get rid of the extra checking. Thanks man!
--
http://mail.python.org/mailman/listinfo/python-list
Wow, why didn't I think of that. Thanks! I'll try it now. By the way I think I
don't need to wrap the single tuples in runtime because I'm declaring that
dictionary anyway beforehand and I could just do it right there. I won't be
adding elements to the tuple.
--
http://mail.python.org/mailman/l
On 02/18/2013 07:52 PM, Jon Reyes wrote:
So I have a dictionary and the key is a number. The values are either a single tuple or a tuple of
tuples. Is there a better way to go about accessing the values of the
dictionary? All the tuples contain four elements.
>
> So say:
> col = {"1": (0,1,2,3
On Jun 14, 12:57 pm, Steve Crook wrote:
> Today I spotted an alternative:
>
> dict[key] = dict.get(key, 0) + 1
>
> Whilst certainly more compact, I'd be interested in views on how
> pythonesque this method is.
It is very pythonesque in the it was the traditional one way to do it
(also one of the
Steve Crook wrote:
> Whilst certainly more compact, I'd be interested in views on how
> pythonesque this method is.
Instead of calling function you could use:
d = {}
d[key] = (key in d and d[key]) + 1
Regards.
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 14 Jun 2011 12:53:11 +, Steve Crook wrote:
> On Tue, 14 Jun 2011 05:37:45 -0700 (PDT), AlienBaby wrote in Message-Id:
> <078c5e9a-8fad-4d4c-b081-f69d0f575...@v11g2000prk.googlegroups.com>:
>
>> How do those methods compare to the one I normally use;
>>
>> try:
>> dict[key]+=1
>> exce
On Tue, 14 Jun 2011 10:57:44 +, Steve Crook wrote:
> Hi all,
>
> I've always done key creation/incrementation using:
>
> if key in dict:
> dict[key] += 1
> else:
> dict[key] = 1
>
> Today I spotted an alternative:
>
> dict[key] = dict.get(key, 0) + 1
>
> Whilst certainly more comp
On Tue, 14 Jun 2011 13:16:47 +0200, Peter Otten wrote in
Message-Id: :
> Your way is usually faster than
>
>> dict[key] = dict.get(key, 0) + 1
Thanks Peter, ran it through Timeit and you're right. It's probably also
easier to read the conditional version, even if it is longer.
> You may also c
On Tue, 14 Jun 2011 05:37:45 -0700 (PDT), AlienBaby wrote in
Message-Id: <078c5e9a-8fad-4d4c-b081-f69d0f575...@v11g2000prk.googlegroups.com>:
> How do those methods compare to the one I normally use;
>
> try:
> dict[key]+=1
> except:
> dict[key]=1
This is a lot slower in percentage terms. You
On Jun 14, 12:16 pm, Peter Otten <__pete...@web.de> wrote:
> Steve Crook wrote:
> > I've always done key creation/incrementation using:
>
> > if key in dict:
> > dict[key] += 1
> > else:
> > dict[key] = 1
>
> Your way is usually faster than
>
> > dict[key] = dict.get(key, 0) + 1
>
> > Whils
Steve Crook wrote:
> I've always done key creation/incrementation using:
>
> if key in dict:
> dict[key] += 1
> else:
> dict[key] = 1
Your way is usually faster than
> dict[key] = dict.get(key, 0) + 1
>
> Whilst certainly more compact, I'd be interested in views on how
> pythonesque t
Ben Finney writes:
> code_by_desc = dict(
> (desc, code) for (code, desc) in codes_to_messages.items())
Bah, I fumbled an edit. Try this::
code_by_desc = dict(
(desc, code) for (code, desc) in desc_by_code.items())
--
\“The reason we come up with new versions
(Replying to Greg, though his original message doesn't appear at Gmane.)
> Greg Lindstrom writes:
>
> > I am working on a project where I'm using dictionaries to hold the
> > translations to codes (i.e., {'1':'Cheddar','2':'Ice
> > Hockey','IL':'Thermostat Broken'}). The bulk of the application
On 11/26/2010 1:13 PM, Greg Lindstrom wrote:
I am working on a project where I'm using dictionaries to hold the
translations to codes (i.e., {'1':'Cheddar','2':'Ice
Hockey','IL':'Thermostat Broken'}). The bulk of the application
requires me to translate codes to their meaning, but it would be ni
Found in Dive in Python 3 :
>>> a_dict = {'a': 1, 'b': 2, 'c': 3}
>>> {value:key for key, value in a_dict.items()}
{1: 'a', 2: 'b', 3: 'c'}
2010/11/26 Burton Samograd
> Greg Lindstrom writes:
>
> > I am working on a project where I'm using dictionaries to hold the
> > translations to codes (i
Greg Lindstrom writes:
> I am working on a project where I'm using dictionaries to hold the
> translations to codes (i.e., {'1':'Cheddar','2':'Ice
> Hockey','IL':'Thermostat Broken'}). The bulk of the application
> requires me to translate codes to their meaning, but it would be nice
> to be abl
Mike P a écrit :
Thanks for the solution above,
The raw data looked like
User-ID,COUNTS
576460840144207854,6
576460821700280307,2
576460783848259584,1
576460809027715074,3
576460825909089607,1
576460817407934470,1
and i used
CSV_INPUT1 = "C:/Example work/Attr_model/Activity_test.csv"
fin1 = op
Thanks for the solution above,
The raw data looked like
User-ID,COUNTS
576460840144207854,6
576460821700280307,2
576460783848259584,1
576460809027715074,3
576460825909089607,1
576460817407934470,1
and i used
CSV_INPUT1 = "C:/Example work/Attr_model/Activity_test.csv"
fin1 = open(CSV_INPUT1, "rb"
[EMAIL PROTECTED] a écrit :
Bruno Desthuilliers:
This doesn't look like a CSV file at all... Is that what you actually
have in the file, or what you get from the csv.reader ???
I presume you are right, the file probably doesn't contain that stuff
like I have assumed in my silly/useless solutio
Bruno Desthuilliers:
> This doesn't look like a CSV file at all... Is that what you actually
> have in the file, or what you get from the csv.reader ???
I presume you are right, the file probably doesn't contain that stuff
like I have assumed in my silly/useless solutions :-)
Bye,
bearophile
--
h
Few solutions, not much tested:
data = """{None: ['User-ID', 'Count']}
{None: ['576460847178667334', '1']}
{None: ['576460847178632334', '8']}"""
lines = iter(data.splitlines())
lines.next()
identity_table = "".join(map(chr, xrange(256)))
result = {}
for line in lines:
parts = line.translate
Mike P a écrit :
Hi All
i have a CSV file that i'm reading in and each line has the look of
the below
{None: ['User-ID', 'Count']}
{None: ['576460847178667334', '1']}
{None: ['576460847178632334', '8']}
This doesn't look like a CSV file at all... Is that what you actually
have in the file, or
Martin Drautzburg a écrit :
> Daniel Nogradi wrote:
>
>
>
What if I want to create a datastructure that can be used in dot
notation without having to create a class, i.e. because those
objects have no behavior at all?
>>>
>>>A class inheriting from dict and implementing __getattr__ a
On 2007-04-22, Martin Drautzburg <[EMAIL PROTECTED]> wrote:
> Daniel Nogradi wrote:
>
>
>>> > What if I want to create a datastructure that can be used in dot
>>> > notation without having to create a class, i.e. because those
>>> > objects have no behavior at all?
>>>
>>> A class inheriting from d
En Mon, 23 Apr 2007 03:14:32 -0300, Martin Drautzburg
<[EMAIL PROTECTED]> escribió:
> I did not notice that I can use a single class (or a module) for
> all my datastructures, because I can "plug in" new attributes into the
> instance without the class knowing about them.
>
> I was mistaken to b
Alex Martelli wrote:
> Martin Drautzburg <[EMAIL PROTECTED]> wrote:
>
>> > mydata = data( )
>> > mydata.foo = 'foo'
>> > mydata.bar = 'bar'
>> >
>> > print mydata.foo
>> > print mydata.bar
>>
>> I am aware of all this.
>> Okay let me rephrase my question: is there a way of using dot
>> notation
Martin Drautzburg <[EMAIL PROTECTED]> wrote:
> > mydata = data( )
> > mydata.foo = 'foo'
> > mydata.bar = 'bar'
> >
> > print mydata.foo
> > print mydata.bar
>
> I am aware of all this.
> Okay let me rephrase my question: is there a way of using dot notation
> without having to create a class?
Martin Drautzburg <[EMAIL PROTECTED]> writes:
> Okay let me rephrase my question: is there a way of using dot
> notation without having to create a class?
Dot notation, e.g. 'foo.bar', is parsed by the interpreter as "access
the attribute named 'bar' of the object 'foo'". Objects have
attributes
Daniel Nogradi wrote:
>> > What if I want to create a datastructure that can be used in dot
>> > notation without having to create a class, i.e. because those
>> > objects have no behavior at all?
>>
>> A class inheriting from dict and implementing __getattr__ and
>> __setattr__ should do the tri
> mydata = data( )
> mydata.foo = 'foo'
> mydata.bar = 'bar'
>
> print mydata.foo
> print mydata.bar
I am aware of all this.
Okay let me rephrase my question: is there a way of using dot notation
without having to create a class?
--
http://mail.python.org/mailman/listinfo/python-list
Martin Drautzburg a écrit :
> This may be pretty obvious for most of you:
>
> When I have an object (an instance of a class "Foo") I can access
> attributes via dot notation:
>
> aFoo.bar
>
> however when I have a dictionary
>
> aDict = {"bar":"something"}
>
> I have to write
Bruno Desthuilliers a écrit :
> Martin Drautzburg a écrit :
>
>> This may be pretty obvious for most of you:
>>
>> When I have an object (an instance of a class "Foo") I can access
>> attributes via dot notation:
>>
>> aFoo.bar
>>
>> however when I have a dictionary
>> aDict = {"ba
> > This may be pretty obvious for most of you:
> >
> > When I have an object (an instance of a class "Foo") I can access
> > attributes via dot notation:
> >
> > aFoo.bar
> >
> > however when I have a dictionary
> >
> > aDict = {"bar":"something"}
> >
> > I have to write
> >
> >
> > This may be pretty obvious for most of you:
> >
> > When I have an object (an instance of a class "Foo") I can access
> > attributes via dot notation:
> >
> > aFoo.bar
> >
> > however when I have a dictionary
> >
> > aDict = {"bar":"something"}
> >
> > I have to write
> >
> >
Martin Drautzburg wrote:
> This may be pretty obvious for most of you:
>
> When I have an object (an instance of a class "Foo") I can access
> attributes via dot notation:
>
> aFoo.bar
>
> however when I have a dictionary
>
> aDict = {"bar":"something"}
>
> I have to write
>
> but I can not create Newdict to be sorted properly.
>
> Where do I make a mistake?
By assuming that dictionaries *can* be sorted.
For more reading:
http://aspn.activestate.com/ASPN/Python/Cookbook/Recipe/52306
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747
They're intrinsical
Lad wrote:
> Sorting seems to be OK,.
> the command
> print key,val
> prints the proper values
> but I can not create Newdict to be sorted properly.
>
> Where do I make a mistake?
> Thank you for help.
Dictionaries are unordered -- the order in which items come out is
unspecified. It's based on
Steven,
Thank you for help;
Here is a code that works in a way I need
A={'c':1,'d':2,'e':3,'f':2}
B={'c':2,'e':1}
if len(A)>=len(B):
Delsi=B
C = A.copy()
else:
Delsi=A
C = B.copy()
for key, value in Delsi.items():
if C.has_key(key):
C[key]=
Fredrik Lundh wrote:
> Lad wrote:
>
>
>> The answer: the values should be added together and assigned to the key
>> That is
>> {'a':1, 'b':5}
>> ( from your example below)
>>
>> Is there a solution?
>>
>
> have you tried coding a solution and failed, or are you just expecting
> people to c
On Wed, 18 Oct 2006 09:31:50 -0700, Lad wrote:
>
> Steven,
> Thank you for your reply and question.
>
>>
>> What should the result be if both dictionaries have the same key?
> The answer: the values should be added together and assigned to the key
> That is
> {'a':1, 'b':5}
> ( from your example
Lad wrote:
> The answer: the values should be added together and assigned to the key
> That is
> {'a':1, 'b':5}
> ( from your example below)
>
> Is there a solution?
have you tried coding a solution and failed, or are you just expecting
people to code for free?
--
http://mail.python.org/mai
Lad wrote:
> Let's suppose I have
>
> a={'c':1,'d':2}
> b={'c':2}
> but
> a.update(b)
> will make
> {'c': 2, 'd': 2}
>
> and I would need
> {'c': 3, 'd': 2}
>
> (because `c` is 1 in `a` dictionary and `c` is 2 in `b` dictionary, so
> 1+2=3)
>
> How can be done that?
dict([(k, a.get(k, 0) + b.ge
Steven,
Thank you for your reply and question.
>
> What should the result be if both dictionaries have the same key?
The answer: the values should be added together and assigned to the key
That is
{'a':1, 'b':5}
( from your example below)
Is there a solution?
Thanks for the reply
L.
>
> a={'a':
> However It does not work as I would need.
> Let's suppose I have
>
> a={'c':1,'d':2}
> b={'c':2}
> but
> a.update(b)
> will make
> {'c': 2, 'd': 2}
>
> and I would need
> {'c': 3, 'd': 2}
Ah...a previously omitted detail.
There are likely a multitude of ways to do it. However, the one
th
Tim Chase wrote:
> > How can I add two dictionaries into one?
> > E.g.
> > a={'a:1}
> > b={'b':2}
> >
> > I need
> >
> > the result {'a':1,'b':2}.
>
> >>> a.update(b)
> >>> a
> {'a':1,'b':2}
>
> -tkc
Thank you ALL for help.
However It does not work as I would need.
Let's suppose I have
a={'c'
On Wed, 18 Oct 2006 08:24:27 -0700, Lad wrote:
> How can I add two dictionaries into one?
> E.g.
> a={'a:1}
> b={'b':2}
>
> I need
>
> the result {'a':1,'b':2}.
>
> Is it possible?
What should the result be if both dictionaries have the same key?
a={'a':1, 'b'=2}
b={'b':3}
should the result
dict(a.items() + b.items())
Lad wrote:
> How can I add two dictionaries into one?
> E.g.
> a={'a:1}
> b={'b':2}
>
> I need
>
> the result {'a':1,'b':2}.
>
> Is it possible?
--
http://mail.python.org/mailman/listinfo/python-list
> How can I add two dictionaries into one?
> E.g.
> a={'a:1}
> b={'b':2}
>
> I need
>
> the result {'a':1,'b':2}.
>>> a.update(b)
>>> a
{'a':1,'b':2}
-tkc
--
http://mail.python.org/mailman/listinfo/python-list
Lad wrote:
> How can I add two dictionaries into one?
> E.g.
> a={'a:1}
> b={'b':2}
>
> I need
>
> the result {'a':1,'b':2}.
>
> Is it possible?
>
> Thank you
> L.
>
>
Yes, use update. Beware that this modifies a dictionary in place rather
than returning a new dictionary.
>>> a={'a':1}
>>> b={
On 18 Oct 2006 08:24:27 -0700, Lad <[EMAIL PROTECTED]> wrote:
> How can I add two dictionaries into one?
> E.g.
> a={'a:1}
> b={'b':2}
>
> I need
>
> the result {'a':1,'b':2}.
>>> a={'a':1}
>>> b={'b':2}
>>> a.update(b)
>>> a
{'a': 1, 'b': 2}
--
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunn
Fredrik Lundh:
> better in what sense?
With better I may mean faster, or needing less memory, or requiring a
shorter code, or other things. It depends on many things, related to
the program I am creating.
Thank you for the timings, you are right, as most times. Sometimes I am
wrong, but I try to
[EMAIL PROTECTED] wrote:
> keys = [key for key in sampledict if sampledict[key] == '1974']
>
> Or better, given:
>
> sampledict = {'the Holy Grail':1975, 'Life of Brian':1979,
> 'Party Political Broadcast':1974,'Mr. Neutron':1974,
> 'Hamlet':1974, 'Light Entertainment War
Avell Diroll:
keys = [key for key in sampledict if sampledict[key] == '1974']
Or better, given:
sampledict = {'the Holy Grail':1975, 'Life of Brian':1979,
'Party Political Broadcast':1974,'Mr. Neutron':1974,
'Hamlet':1974, 'Light Entertainment War':1974}
keys = [key
Michael Malinowski wrote:
(snip)
> However, I am curious to know if its possible to get the key from giving
> a value (basically the opposite of what I did above, instead of getting
> a value from a key, I want the key from a value). Is there a way of
> doing this? Or would I need to cycle all the
On 8/28/06, Steve Holden <[EMAIL PROTECTED]> wrote:
Andre Meyer wrote:> Hi all>> I have the following question: I need a representation of a physically> inspired environment. The environment contains a large number of objects> with varying attributes. There may be classes of objects, but there is
>
Andre Meyer wrote:
> Hi all
>
> I have the following question: I need a representation of a physically
> inspired environment. The environment contains a large number of objects
> with varying attributes. There may be classes of objects, but there is
> not necessarily a strictly defined hierarc
rh0dium wrote:
> Hi all,
>
> Can someone help me out. I am trying to determing for each run whether
> or not the test should pass or fail but I can't seem to access the
> results ..
>
> Alternatively can someone suggest a better structure ( and a lesson as
> to the reasoning ) that would be great
rh0dium a écrit :
> Hi all,
>
> Can someone help me out. I am trying to determing for each run whether
> or not the test should pass or fail but I can't seem to access the
> results ..
>
(snip)
> cells={}
>
> cells["NOR3X1"]= {
> 'run' : [ 'lvs', 'drc' ],
>
rh0dium wrote:
> Hi all,
>
> Can someone help me out. I am trying to determing for each run whether
> or not the test should pass or fail but I can't seem to access the
> results ..
>
> Alternatively can someone suggest a better structure ( and a lesson as
> to the reasoning ) that would be grea
> Can someone help me out. I am trying to determing for each run whether
> or not the test should pass or fail but I can't seem to access the
> results ..
>
> Alternatively can someone suggest a better structure ( and a lesson as
> to the reasoning ) that would be great too!!
Flat is better than
rh0dium wrote:
> Hi all,
>
> Can someone help me out. I am trying to determing for each run whether
> or not the test should pass or fail but I can't seem to access the
> results ..
>
> Alternatively can someone suggest a better structure ( and a lesson as
> to the reasoning ) that would be grea
On 7 Oct 2005 14:23:49 -0700, "Rob Conner" <[EMAIL PROTECTED]> wrote:
>I dont know how to do this and can't think of a simple way to.
>
>All I want is a dictionary where two keys point to the same object.
>(to steal the ascii art from
>http://starship.python.net/crew/mwh/hacks/objectthink.html)
>I
Rob Conner wrote:
> I dont know how to do this and can't think of a simple way to.
>
> All I want is a dictionary where two keys point to the same object.
> (to steal the ascii art from
> http://starship.python.net/crew/mwh/hacks/objectthink.html)
> I want sometihng like this:
>
> ,--.
thanks. Looks good.
--
http://mail.python.org/mailman/listinfo/python-list
Bloke wrote:
>I've been trying to find a Python tutorial on threading - does anyone
>have a reference?
>
>Rob
>
>
>
You could try this:
http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf
J
--
http://mail.python.org/mailman/listinfo/python-list
I've been trying to find a Python tutorial on threading - does anyone
have a reference?
Rob
--
http://mail.python.org/mailman/listinfo/python-list
[Gary Robinson]
> I know the Global Interpreter Lock ensures that only one python thread
> has access to the interpreter at a time, which prevents a lot of
> situations where one thread might step on another's toes.
Not really. The CPython implementation's C code relies on the GIL in
many ways t
Gary Robinson <[EMAIL PROTECTED]> writes:
> As far as I can tell, if the Python bytecodes that cause dictionary
> modifications are atomic, then there should be no problem. But I don't
> know that they are because I haven't looked at the bytecodes.
Depending on behavior like that is asking for
Tony Meyer wrote:
[a for a in list] (or a[:]) makes a copy of a list.
or list(a)
STeVe
--
http://mail.python.org/mailman/listinfo/python-list
On Monday 07 March 2005 11:09 pm, gf gf wrote:
> I'd like to associate certain lists with keywords, and
> retrieve them. But this is not possible as lists are
> not hashable.
>
> What is the best workaround? I don't mind making my
> lists immutable. Is there a way to tupelize them?
> I tried my
> I'd like to associate certain lists with keywords, and
> retrieve them. But this is not possible as lists are
> not hashable.
A dictionary's values don't have to be hashable, so if the keywords are the
keys in the dictionary, this would work.
>>> d = {}
>>> d['key1'] = [1,2,3]
>>> d['key2'] =
gf gf wrote:
I'd like to associate certain lists with keywords, and
retrieve them. But this is not possible as lists are
not hashable.
Do you want
mydict[mylist] = mykey
or
mydict[mykey] = mylist
?
The former is not possible with lists for the reason you noted. The
latter, however, works just
gf gf wrote:
I'd like to associate certain lists with keywords, and
retrieve them. But this is not possible as lists are
not hashable.
You can convert them to tuples with the `tuple' function:
aDictionary[tuple(aList)] = aKeyword
> What is the best workaround? I don't mind making my
> lis
94 matches
Mail list logo