Re: Lists: Converting Double to Single

2007-02-26 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > So I have lists that look like this: [1, 2, 3, 4, 5]. When I > concatenate lists, I end up with a list of lists that looks like > this: [[1, 2, 3. 4, 5]. [6, 7. 8, 9. 10]]. Really? >>> [1, 2, 3, 4, 5] + [6, 7, 8, 9, 10] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > Then, I aver

Re: How to Read Bytes from a file

2007-03-01 Thread Leif K-Brooks
Alex Martelli wrote: > You should probaby prepare before the loop a mapping from char to number > of 1 bits in that char: > > m = {} > for c in range(256): > m[c] = countones(c) Wouldn't a list be more efficient? m = [countones(c) for c in xrange(256)] -- http://mail.python.org/mailman/listin

Re: Inexplicable behaviour of

2006-04-23 Thread Leif K-Brooks
Fabiano Sidler wrote: > Have a look to the following lines of code: > --- snip --- > class Foo: pass > def bar(): pass > Foo.bar = bar > --- snap --- > > Why does 'bar.__get__(Foo) is Foo.bar' evaluate to False here? Did I > misunderstand the descriptor protocol? bar.__get__(None, Bar) is what yo

Re: modifying iterator value.

2006-04-26 Thread Leif K-Brooks
chun ping wang wrote: > i want to modify an iterator value. > > for x in someList >x = 1 for index, value in enumerate(someList): someList[index] = 1 -- http://mail.python.org/mailman/listinfo/python-list

Re: scope of variables

2006-05-03 Thread Leif K-Brooks
Gary Wessle wrote: > the example was an in-accuretlly representation of a the problem I am > having. my apologies. > > a = [] > def prnt(): >print len(a) > prnt > > > I expect to get 0 "the length of list a" Python requires parenthesis to call a function. >>> a = [] >>> def prnt(

Re: which is better, string concatentation or substitution?

2006-05-07 Thread Leif K-Brooks
John Salerno wrote: > My initial feeling is that concatenation might take longer than > substitution Doesn't look that way: [EMAIL PROTECTED]:~$ python -m timeit "'%s\n\n' % 'foobar'" 100 loops, best of 3: 0.6 usec per loop [EMAIL PROTECTED]:~$ python -m timeit "'' + 'foobar' + '\n\n'" 1

Re: which is better, string concatentation or substitution?

2006-05-07 Thread Leif K-Brooks
fuzzylollipop wrote: > niether .join() is the fastest Please quote what you're replying to. No, it's the slowest: [EMAIL PROTECTED]:~$ python -m timeit "'%s\n\n' % 'foobar'" 100 loops, best of 3: 0.607 usec per loop [EMAIL PROTECTED]:~$ python -m timeit "'' + 'foobar' + '\n\n'" 100 loops

Re: Multi-line lambda proposal.

2006-05-08 Thread Leif K-Brooks
Kaz Kylheku wrote: > But suppose that the expression and the multi-line lambda body are > reordered? That is to say, the expression is written normally, and the > mlambda expressions in it serve as /markers/ indicating that body > material follows. This results in the most Python-like solution. I

Re: enumerate() question

2006-05-22 Thread Leif K-Brooks
Gregory Petrosyan wrote: > Hello! > I have a question for the developer[s] of enumerate(). Consider the > following code: > > for x,y in coords(dots): > print x, y > > When I want to iterate over enumerated sequence I expect this to work: > > for i,x,y in enumerate(coords(dots)): > print

Re: how to convert string

2006-04-05 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > I want to print number 0 to 9 in one line like this > 0 1 2 3 4 5 6 7 8 9 > > if I do like this, it prints in different lines > > for i in xrange(10): > print i for i in xrange(10): print i, > so i tried like this > > str = "" > for i in xrange(10): > st

Re: How to determine if a line of python code is a continuation of the line above it

2006-04-09 Thread Leif K-Brooks
Sandra-24 wrote: > I'm not sure how complex this is, I've been brainstorming a little, and > I've come up with: from tokenize import generate_tokens, NL, NEWLINE from cStringIO import StringIO def code_lines(source): """Takes Python source code (as either a string or file-like object) a

<    1   2   3