Re: Learning question...

2008-05-07 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Any idea why the following program does not work? I was learning IO on | Python and the following generates a TypeError: range() integer end | argument expected, got str. | I am a beginner. | | | # prin

Re: Learning question...

2008-05-07 Thread swapsun
On May 7, 8:42 am, Thomas Woelz <[EMAIL PROTECTED]> wrote: > On 7 maio, 09:25, [EMAIL PROTECTED] wrote: > > > Any idea why the following program does not work? I was learning IO on > > Python and the following generates a TypeError: range() integer end > > argument expected, got str. > > I am a beg

Re: Learning question...

2008-05-07 Thread swapsun
On May 7, 8:36 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Any idea why the following program does not work? I was learning IO on > > Python and the following generates a TypeError: range() integer end > > argument expected, got str. > > I am a beginner. > > Bec

Re: Learning question...

2008-05-07 Thread Thomas Woelz
On 7 maio, 09:25, [EMAIL PROTECTED] wrote: > Any idea why the following program does not work? I was learning IO on > Python and the following generates a TypeError: range() integer end > argument expected, got str. > I am a beginner. > > > # print input name (str k

Re: Learning question...

2008-05-07 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote: > Any idea why the following program does not work? I was learning IO on > Python and the following generates a TypeError: range() integer end > argument expected, got str. > I am a beginner. Because raw_input does return you as string which you need explicitly convert to

Learning question...

2008-05-07 Thread swapsun
Any idea why the following program does not work? I was learning IO on Python and the following generates a TypeError: range() integer end argument expected, got str. I am a beginner. # print input name (str k), j times using raw_input def hello(): j=raw_input

Re: dict invert - learning question

2008-05-03 Thread Jerry Hill
On Sat, May 3, 2008 at 4:29 PM, dave <[EMAIL PROTECTED]> wrote: > here is a piece of code I wrote to check the frequency of values and switch > them around to keys in a new dictionary. Just to measure how many times a > certain key occurs: > > def invert(d): > inv = {} > for key

Re: dict invert - learning question

2008-05-03 Thread George Sakkis
On May 3, 5:12 pm, dave <[EMAIL PROTECTED]> wrote: > thanks Duncan and Arnaud. > > I'm learning Python from the "How to Think Like a Python Programmer" > book by Allen Downey.  My first try used the "inv[val] = [key]" and > then the next problem was to incorporate the "D.setdefault(...)" method. >

Re: dict invert - learning question

2008-05-03 Thread mrkafk
On 4 Maj, 01:27, [EMAIL PROTECTED] wrote: > >>> a={1:'a', 2:'b', 3:'c'} Oops, it should obviously be: >>> dict(zip(a.values(), a.keys())) {'a': 1, 'c': 3, 'b': 2} -- http://mail.python.org/mailman/listinfo/python-list

Re: dict invert - learning question

2008-05-03 Thread mrkafk
Assuming all the values are unique: >>> a={1:'a', 2:'b', 3:'c'} >>> dict(zip(a.keys(), a.values())) {1: 'a', 2: 'b', 3: 'c'} The problem is you obviously can't assume that in most cases. Still, zip() is very useful function. -- http://mail.python.org/mailman/listinfo/python-list

Re: dict invert - learning question

2008-05-03 Thread dave
thanks Duncan and Arnaud. I'm learning Python from the "How to Think Like a Python Programmer" book by Allen Downey. My first try used the "inv[val] = [key]" and then the next problem was to incorporate the "D.setdefault(...)" method. Thank you for your help. I'm always amazed how kind peop

Re: dict invert - learning question

2008-05-03 Thread Arnaud Delobelle
dave <[EMAIL PROTECTED]> writes: > Hello, > > here is a piece of code I wrote to check the frequency of values and > switch them around to keys in a new dictionary. Just to measure how > many times a certain key occurs: > > def invert(d): > inv = {} > for key in d: > val

Re: dict invert - learning question

2008-05-03 Thread Duncan Booth
dave <[EMAIL PROTECTED]> wrote: > Hello, > > here is a piece of code I wrote to check the frequency of values and > switch them around to keys in a new dictionary. Just to measure how > many times a certain key occurs: > > def invert(d): > inv = {} > for key in d: > val =

dict invert - learning question

2008-05-03 Thread dave
Hello, here is a piece of code I wrote to check the frequency of values and switch them around to keys in a new dictionary. Just to measure how many times a certain key occurs: def invert(d): inv = {} for key in d: val = d[key] if val not in in