Re: [Tutor] Projects (fwd)

2008-01-25 Thread Ricardo Aráoz
Tiger12506 wrote: >> Nope, if you read the code you'll see the only mapping done is up to 20 >> and then by tens up to 100, that's all. >> The same code could be used with a list, you'd only have to change the >> exception name. > > I see. There were "..." in between each of the tens entries which

Re: [Tutor] Projects (fwd)

2008-01-24 Thread Tiger12506
> Nope, if you read the code you'll see the only mapping done is up to 20 > and then by tens up to 100, that's all. > The same code could be used with a list, you'd only have to change the > exception name. I see. There were "..." in between each of the tens entries which I took to mean that "big

Re: [Tutor] Projects (fwd)

2008-01-24 Thread Ricardo Aráoz
Tiger12506 wrote: >> Isn't dictionary access faster than list access? Why are three lists >> 'much more efficient'? > > Oh no, no, no. Dictionaries are faster when you are *searching through* for > a particular value. If you already know the index of the item in the list, > lists are much faste

Re: [Tutor] Projects (fwd)

2008-01-23 Thread bob gailer
Danny Yoo wrote: > [snip] > First, it ignores zero, which is a cardinal sin. Or is it an ordinal sin? [snip] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Projects (fwd)

2008-01-23 Thread John Fouhy
On 24/01/2008, Ricardo Aráoz <[EMAIL PROTECTED]> wrote: > Isn't dictionary access faster than list access? Why are three lists > 'much more efficient'? Well, not necessarily. If you want a dictionary, you could use a list of tuples: myDict = [('a', 'one'), ('b', 'two), ('c', 'three')] Then you

Re: [Tutor] Projects (fwd)

2008-01-23 Thread Tiger12506
> Isn't dictionary access faster than list access? Why are three lists > 'much more efficient'? Oh no, no, no. Dictionaries are faster when you are *searching through* for a particular value. If you already know the index of the item in the list, lists are much faster. Dictionaries are hash ba

Re: [Tutor] Projects (fwd)

2008-01-23 Thread Tiger12506
> This could be written much more efficiently. It can be done with only > these > lists~ > ones = > ['zero','one','two','three','four','five','six','seven','eight','nine'] > teens = > ['ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen'] What is it

Re: [Tutor] Projects (fwd)

2008-01-23 Thread Ricardo Aráoz
Tiger12506 wrote: >> up to a thousand (not tested) >> >> words = {0:'zero', 1:'one', 2:'two', 3:'three', ... , 10:'ten', >> 11:'eleven', 12:'twelve', ..., 19:'nineteen', >> 20:'twenty', , 90:'ninety', 100:'one hundred' } >> def digitToString(n) : >>try : >>retStr = words[n]

Re: [Tutor] Projects (fwd)

2008-01-23 Thread Tiger12506
> up to a thousand (not tested) > > words = {0:'zero', 1:'one', 2:'two', 3:'three', ... , 10:'ten', > 11:'eleven', 12:'twelve', ..., 19:'nineteen', > 20:'twenty', , 90:'ninety', 100:'one hundred' } > def digitToString(n) : >try : >retStr = words[n] >except KeyError : >

Re: [Tutor] Projects (fwd)

2008-01-23 Thread Ricardo Aráoz
Danny Yoo wrote: > Hi Jason, > > > Looking back at that Java code: > > > static String convertDigitToEnglish(int d) { > switch ( d ) > { >case 1: return "one"; >case 2: return "two"; >case 3

Re: [Tutor] Projects (fwd)

2008-01-23 Thread Danny Yoo
Hi Jason, Looking back at that Java code: static String convertDigitToEnglish(int d) { switch ( d ) { case 1: return "one"; case 2: return "two"; case 3: return "three"; case 4: retu