Re: Elementary string-formatting

2008-01-14 Thread Odysseus
In article <[EMAIL PROTECTED]>, John Machin <[EMAIL PROTECTED]> wrote: > > div operator? The integer division operator is // Yes, sorry, that's what I meant. -- Odysseus -- http://mail.python.org/mailman/listinfo/python-list

Re: Elementary string-formatting

2008-01-13 Thread Matt Nordhoff
Odysseus wrote: > Hello, group: I've just begun some introductory tutorials in Python. > Taking off from the "word play" exercise at > > > > I've written a mini-program to tabulate the number of characters in each > word in a fi

Re: Elementary string-formatting

2008-01-13 Thread Odysseus
In article <[EMAIL PROTECTED]>, Gary Herron <[EMAIL PROTECTED]> wrote: > Odysseus wrote: > > > > print '%2u %6u %4.2f' % \ > > (i, wordcounts[i], 100.0 * wordcounts[i] / wordcounts[0]) > > > Using 4.2 is the problem. The first digit (your 4) give the total > number of characters to use for

Re: Elementary string-formatting

2008-01-13 Thread John Machin
On Jan 13, 8:43 pm, Odysseus <[EMAIL PROTECTED]> wrote: > In article > <[EMAIL PROTECTED]>, > Roberto Bonvallet <[EMAIL PROTECTED]> wrote: > > > Put this at the beginning of your program: > > > from __future__ import division > > > This forces all divisions to yield floating points values: > >

Re: Elementary string-formatting

2008-01-13 Thread Odysseus
In article <[EMAIL PROTECTED]>, Roberto Bonvallet <[EMAIL PROTECTED]> wrote: > Put this at the beginning of your program: > > from __future__ import division > > This forces all divisions to yield floating points values: Thanks for the tip. May I assume the div operator will still behave

Re: Elementary string-formatting

2008-01-13 Thread Odysseus
In article <[EMAIL PROTECTED]>, John Machin <[EMAIL PROTECTED]> wrote: > > You obviously haven't tried float(n / m), or you wouldn't be asking. True, it was a very silly idea. > Most legible and slowest first: > 1. float(n) / float(m) > 2. n / float(m) > 3. 1.0 * n / m > Recommendation: go

Re: Elementary string-formatting

2008-01-12 Thread Roberto Bonvallet
On Jan 12, 10:15 pm, Odysseus <[EMAIL PROTECTED]> wrote: > P.S. Is there a preferable technique for forcing floating-point division > of two integers to that used above, multiplying by "100.0" first? Put this at the beginning of your program: from __future__ import division This forces all d

Re: Elementary string-formatting

2008-01-12 Thread John Machin
On Jan 13, 3:15 pm, Odysseus <[EMAIL PROTECTED]> wrote: [snip] > > P.S. Is there a preferable technique for forcing floating-point division > of two integers to that used above, multiplying by "100.0" first? What > about if I just wanted a ratio: is "float(n / m)" better than "1.0 * n / > m"? > Od

Re: Elementary string-formatting

2008-01-12 Thread Gary Herron
Odysseus wrote: > Hello, group: I've just begun some introductory tutorials in Python. > Taking off from the "word play" exercise at > > > > I've written a mini-program to tabulate the number of characters in each > word in a file

Elementary string-formatting

2008-01-12 Thread Odysseus
Hello, group: I've just begun some introductory tutorials in Python. Taking off from the "word play" exercise at I've written a mini-program to tabulate the number of characters in each word in a file. Once the data have been co