Re: dictionary error: list assignment index out of range

2011-01-28 Thread Octavian Rasnita
From: Vaduvoiu Tiberiu > Well, to quote firefox: this is embarrassing. I've realized the dictionary initialization is wrong, as [] means its a tuple, I should use {}. That's why I > don't like working nights..it's only in the morning when you start seeing things better. I apologize for the ma

Re: dictionary error: list assignment index out of range

2011-01-27 Thread Vaduvoiu Tiberiu
for the mail. Cheers From: Vaduvoiu Tiberiu To: python-list@python.org Sent: Fri, January 28, 2011 9:34:57 AM Subject: dictionary error: list assignment index out of range Hy everyone, I'm trying to learng python for a week or two and there's a thing that is re

dictionary error: list assignment index out of range

2011-01-27 Thread Vaduvoiu Tiberiu
ed self.visited = [] and in the function where i check if city was visited: cityNumber = 1 #example if (not cityNumber in self.visited): #do some stuff self.visited[cityNumber] = "true" Apparently the last line causes the error: list assignment index out of range. I read that

Re: list assignment using concatenation "*"

2006-02-24 Thread Steve R. Hastings
I suggest you should build your list using a list comprehension: >>>a = [[0]*3 for i in range(3)] >>>a [[0, 0, 0], [0, 0, 0], [0, 0, 0]] >>>a[0][1] = 1 [[0, 1, 0], [0, 0, 0], [0, 0, 0]] -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.

Re: list assignment using concatenation "*"

2006-02-24 Thread Steve R. Hastings
> if I do: > > a = [ [0] * 3 ] * 3 > a[0][1] = 1 > > I get > > a = [[0,1,0],[0,1,0],[0,1,0]] The language reference calls '*' the "repetition" operator. It's not making copies of what it repeats, it is repeating it. Consider the following code: >>> a = [] >>> b = [] >>> a == b True >>> a is

list assignment using concatenation "*"

2006-02-24 Thread liquid
If I do: a = [ [0,0,0], [0,0,0], [0,0,0] ] a[0][1] = 1 I get: a = [ [0,1,0],[0,0,0],[0,0,0] ] as expected But if I do: a = [ [0] * 3 ] * 3 a[0][1] = 1 I get a = [[0,1,0],[0,1,0],[0,1,0]] AFAIC, "*" is supposed to generate multiple copies of the given token. Therefore I thought both cases w

Re: list assignment

2006-02-23 Thread Bernhard Herzog
Norvell Spearman <[EMAIL PROTECTED]> writes: > Lutz and Ascher have tuple and list assignment as separate entries in > their assignment statement forms table so I was expecting there to be > some difference; thanks for setting me straight. In older Python versions there was a dif

Re: list assignment

2006-02-22 Thread Norvell Spearman
Jeffrey Schwab wrote: > TMTOWTDI, after all. :) A bit ironic that that's the official motto of Perl, don't you think? -- Norvell Spearman -- http://mail.python.org/mailman/listinfo/python-list

Re: list assignment

2006-02-22 Thread Norvell Spearman
Raymond Hettinger wrote: > It's not different. They are ways of writing the same thing. Lutz and Ascher have tuple and list assignment as separate entries in their assignment statement forms table so I was expecting there to be some difference; thanks for setting me straight. --

Re: list assignment

2006-02-22 Thread Jeffrey Schwab
Raymond Hettinger wrote: >> [spam, ham] = ['yum', 'YUM'] >> >>I don't see how this is any different than a tuple unpacking assignment: >> >> >>> a, b = 1, 2 > > > It's not different. They are ways of writing the same thing. TMTOWTDI, after all. :) -- http://mail.python.org/mailman/list

Re: list assignment

2006-02-22 Thread Raymond Hettinger
> [spam, ham] = ['yum', 'YUM'] > > I don't see how this is any different than a tuple unpacking assignment: > > >>> a, b = 1, 2 It's not different. They are ways of writing the same thing. Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list

list assignment

2006-02-22 Thread Norvell Spearman
In "Learning Python," by Lutz and Ascher, there's a table showing different assignment statement forms. One form shown is list assignment. The authors give this as an example: [spam, ham] = ['yum', 'YUM'] I don't see how this is any dif