On Oct 17, 10:22 am, Terry Reedy tjre...@udel.edu wrote:
On 10/16/2012 9:54 PM, Kevin Anthony wrote:
I've been teaching myself list comprehension, and i've run across
something i'm not able to convert.
list comprehensions specifically abbreviate the code that they are
(essentially)
On 17/10/12 09:13:57, rusi wrote:
On Oct 17, 10:22 am, Terry Reedy tjre...@udel.edu wrote:
On 10/16/2012 9:54 PM, Kevin Anthony wrote:
I've been teaching myself list comprehension, and i've run across
something i'm not able to convert.
list comprehensions specifically abbreviate the code
On 10/17/2012 12:43 AM, Kevin Anthony wrote:
Is it not true that list comprehension is much faster the the for loops?
If it is not the correct way of doing this, i appoligize.
Like i said, I'm learing list comprehension.
(Please don't top-post; it ruins the ordering. In these forums, put
On Oct 17, 5:33 pm, Dave Angel d...@davea.name wrote:
On 10/17/2012 12:43 AM, Kevin Anthony wrote: Is it not true that list
comprehension is much faster the the for loops?
If it is not the correct way of doing this, i appoligize.
Like i said, I'm learing list comprehension.
list
On Oct 17, 7:06 pm, rusi rustompm...@gmail.com wrote:
On Oct 17, 5:33 pm, Dave Angel d...@davea.name wrote:
On 10/17/2012 12:43 AM, Kevin Anthony wrote: Is it not true that list
comprehension is much faster the the for loops?
If it is not the correct way of doing this, i appoligize.
On 10/17/2012 10:06 AM, rusi wrote:
On Oct 17, 5:33 pm, Dave Angel d...@davea.name wrote:
On 10/17/2012 12:43 AM, Kevin Anthony wrote: Is it not true that list
comprehension is much faster the the for loops?
If it is not the correct way of doing this, i appoligize.
Like i said, I'm learing
Dave Angel於 2012年10月17日星期三UTC+8下午10時37分01秒寫道:
On 10/17/2012 10:06 AM, rusi wrote:
On Oct 17, 5:33 pm, Dave Angel d...@davea.name wrote:
On 10/17/2012 12:43 AM, Kevin Anthony wrote: Is it not true that list
comprehension is much faster the the for loops?
If it is not the correct
On Oct 17, 7:37 pm, Dave Angel d...@davea.name wrote:
And I'd wager all the improvement is in the inner loop, the dot() function.
Sorry -- red herring!
Changing
def mm1(a,b): return [[sum(x*y for x,y in zip(ra,rb)) for rb in
zip(*b)] for ra in a]
to
def mm1(a,b): return [[sum([x*y for x,y
rusi於 2012年10月17日星期三UTC+8下午10時50分11秒寫道:
On Oct 17, 7:37 pm, Dave Angel d...@davea.name wrote:
And I'd wager all the improvement is in the inner loop, the dot() function.
Sorry -- red herring!
Changing
def mm1(a,b): return [[sum(x*y for x,y in zip(ra,rb)) for rb in
On 10/17/2012 3:13 AM, rusi wrote:
On Oct 17, 10:22 am, Terry Reedy tjre...@udel.edu wrote:
On 10/16/2012 9:54 PM, Kevin Anthony wrote:
I've been teaching myself list comprehension, and i've run across
something i'm not able to convert.
My response is to the part Kevin could *not* convert,
On 17 October 2012 06:09, Dwight Hutto dwightdhu...@gmail.com wrote:
On Wed, Oct 17, 2012 at 12:43 AM, Kevin Anthony
kevin.s.anth...@gmail.com wrote:
Is it not true that list comprehension is much faster the the for loops?
If it is not the correct way of doing this, i appoligize.
Like i
I've been teaching myself list comprehension, and i've run across something
i'm not able to convert.
here's the original code for matrix multiplcation
retmatrix = Matrix(self.__row,other.__col)
for m in range(0,retmatrix.__row):
for n in range(0,retmatrix.__col):
product = 0
On 10/16/2012 09:54 PM, Kevin Anthony wrote:
I've been teaching myself list comprehension, and i've run across something
i'm not able to convert.
here's the original code for matrix multiplcation
retmatrix = Matrix(self.__row,other.__col)
for m in range(0,retmatrix.__row):
for n in
On Tue, Oct 16, 2012 at 10:13 PM, Dwight Hutto dwightdhu...@gmail.com wrote:
On Tue, Oct 16, 2012 at 9:54 PM, Kevin Anthony
kevin.s.anth...@gmail.com wrote:
I've been teaching myself list comprehension, and i've run across something
i'm not able to convert.
here's the original code for
On Tue, Oct 16, 2012 at 10:13 PM, Dave Angel d...@davea.name wrote:
On 10/16/2012 09:54 PM, Kevin Anthony wrote:
I've been teaching myself list comprehension, and i've run across something
i'm not able to convert.
here's the original code for matrix multiplcation
retmatrix =
On Oct 17, 7:14 am, Dave Angel d...@davea.name wrote:
On 10/16/2012 09:54 PM, Kevin Anthony wrote:
I've been teaching myself list comprehension, and i've run across something
i'm not able to convert.
here's the original code for matrix multiplcation
retmatrix =
Is it not true that list comprehension is much faster the the for loops?
If it is not the correct way of doing this, i appoligize.
Like i said, I'm learing list comprehension.
Thanks
Kevin
On Oct 16, 2012 10:14 PM, Dave Angel d...@davea.name wrote:
On 10/16/2012 09:54 PM, Kevin Anthony wrote:
On Wed, Oct 17, 2012 at 12:43 AM, Kevin Anthony
kevin.s.anth...@gmail.com wrote:
Is it not true that list comprehension is much faster the the for loops?
If it is not the correct way of doing this, i appoligize.
Like i said, I'm learing list comprehension.
I thought it was matrix
On 10/16/2012 9:54 PM, Kevin Anthony wrote:
I've been teaching myself list comprehension, and i've run across
something i'm not able to convert.
list comprehensions specifically abbreviate the code that they are
(essentially) equivalent to.
res = []
for item in source:
res.append(f(item))
I understand the following:
In [79]: instansie
instansie
Out[79]: 'Mangosuthu Technikon'
In [80]: t = [x.alt_name for x in lys]
t = [x.alt_name for x in lys]
In [81]: t
t
Out[81]: []
In [82]: t.append(instansie)
t.append(instansie)
In [83]: t
t
Out[83]: ['Mangosuthu Technikon']
But then why
On 29 February 2012 13:52, Johann Spies johann.sp...@gmail.com wrote:
In [82]: t.append(instansie)
t.append(instansie)
In [83]: t
t
Out[83]: ['Mangosuthu Technikon']
In [84]: t = [x.alt_name for x in lys].append(instansie)
t = [x.alt_name for x in lys].append(instansie)
In [85]: t
t
In mailman.298.1330534919.3037.python-l...@python.org James Broadhead
jamesbroadh...@gmail.com writes:
On 29 February 2012 13:52, Johann Spies johann.sp...@gmail.com wrote:
In [82]: t.append(instansie)
t.append(instansie)
In [83]: t
t
Out[83]: ['Mangosuthu Technikon']
In [84]: t
On Wed, Feb 29, 2012 at 5:52 AM, Johann Spies johann.sp...@gmail.com wrote:
I understand the following:
In [79]: instansie
instansie
Out[79]: 'Mangosuthu Technikon'
In [80]: t = [x.alt_name for x in lys]
t = [x.alt_name for x in lys]
In [81]: t
t
Out[81]: []
In [82]:
On 2/29/2012 8:52 AM, Johann Spies wrote:
Please post plain text, the standard for all python.org mailing lists
and corresponding newsgroups, and not html. Some readers print the html
as plain text, which is confusing and obnoxious. Other like mine, do
skip the plain text version and print
Steven D'Aprano st...@remove-this-cybersource.com.au writes:
On Thu, 07 May 2009 13:28:10 -0400, J Kenneth King wrote:
Steven D'Aprano ste...@remove.this.cybersource.com.au writes:
On Wed, 06 May 2009 09:48:51 -0400, J Kenneth King wrote:
Emile van Sebille em...@fenx.com writes:
On
Terry Reedy tjre...@udel.edu writes:
J Kenneth King wrote:
Keep in mind that nested comprehensions are still available because
they do have a use case that justifies their existence.
Nested comprehensions are available because because the syntax makes
them available by default and making a
On Thu, 07 May 2009 13:28:10 -0400, J Kenneth King wrote:
Steven D'Aprano ste...@remove.this.cybersource.com.au writes:
On Wed, 06 May 2009 09:48:51 -0400, J Kenneth King wrote:
Emile van Sebille em...@fenx.com writes:
On 5/5/2009 9:15 AM J Kenneth King said...
List comprehensions can
Steven D'Aprano wrote:
If you’ve got the stomach for it, list comprehensions can be nested.
They are a powerful tool but – like all powerful tools – they need to be
used carefully, if at all.
How does this discourage the use of list comprehensions? At most, it
warns that complicated list
Lie Ryan wrote:
Steven D'Aprano wrote:
If you’ve got the stomach for it, list comprehensions can be nested.
They are a powerful tool but – like all powerful tools – they need to be
used carefully, if at all.
How does this discourage the use of list comprehensions? At most, it
warns that
Scott David Daniels wrote:
John Posner wrote:
Shane Geiger wrote:
if type(el) == list or type(el) is tuple:
A tiny improvement:
if type(el) in (list, tuple):
or (even better)
if isinstance(el, (list, tuple))
However, it is my contention that you shouldn't be flattening by
Steven D'Aprano ste...@remove.this.cybersource.com.au writes:
On Wed, 06 May 2009 09:48:51 -0400, J Kenneth King wrote:
Emile van Sebille em...@fenx.com writes:
On 5/5/2009 9:15 AM J Kenneth King said...
List comprehensions can make a reader of your code apprehensive
because it can read
J Kenneth King wrote:
Keep in mind that nested comprehensions are still available because
they do have a use case that justifies their existence.
Nested comprehensions are available because because the syntax makes
them available by default and making a fiddly exception would be
contrary to
On May 6, 2:10 pm, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
It's precisely the indentation and colons (plus newlines) that makes
nested for-loops easier to read than list-comps with multiple fors.
You can get back *nearly* all the readability by splitting the list comp
Ross wrote:
If I have a list of tuples a = [(1,2), (3,4), (5,6)], and I want to
return a new list of each individual element in these tuples, I can do
it with a nested for loop but when I try to do it using the list
comprehension b = [j for j in i for i in a], my output is b =
[5,5,5,6,6,6]
On May 5, 11:36 pm, alex23 wuwe...@gmail.com wrote:
Apart from the presence of 'item' at the beginning of the
list comprehension as opposed to 'b.append(item)' at the
end of the for-loop, how exactly does the listcomp force
you to bounce [..] back and forth to follow the logic?
It's
Emile van Sebille em...@fenx.com writes:
On 5/5/2009 9:15 AM J Kenneth King said...
List comprehensions can make a reader of your code apprehensive
because it can read like a run-on sentence and thus be difficult to
parse. The Python documentation discourages their use and I believe
for
John Yeung schreef:
Essentially, if you see [B A] over and over and over again, when
finally confronted with LCs of more elements, it's not immediately
clear that the pattern of increasing nestedness is
[B A] = [C A B] = [D A B C] = etc.
rather than
[B A] = [C B A] = [D C B A] =
On 5/6/2009 6:48 AM J Kenneth King said...
Emile van Sebille em...@fenx.com writes:
On 5/5/2009 9:15 AM J Kenneth King said...
The Python documentation discourages their use and I believe
for good reason.
Can you provide a link for this? I'd like to see specifically what's
being
On Wed, 06 May 2009 09:48:51 -0400, J Kenneth King wrote:
Emile van Sebille em...@fenx.com writes:
On 5/5/2009 9:15 AM J Kenneth King said...
List comprehensions can make a reader of your code apprehensive
because it can read like a run-on sentence and thus be difficult to
parse. The
Emile van Sebille em...@fenx.com writes:
On 5/1/2009 7:31 AM J Kenneth King said...
Chris Rebert c...@rebertia.com writes:
b = []
for pair in a:
for item in pair:
b.append(item)
This is much more clear than a nested comprehension.
I love comprehensions, but abusing them can
On 5/5/2009 9:15 AM J Kenneth King said...
List comprehensions can make a reader of your code apprehensive
because it can read like a run-on sentence and thus be difficult to
parse. The Python documentation discourages their use and I believe
for good reason.
Can you provide a link for this?
On Fri, 2009-05-01 at 13:00 -0400, John Posner wrote:
Shane Geiger wrote:
if type(el) == list or type(el) is tuple:
A tiny improvement:
if type(el) in (list, tuple):
Another alternative, which might be useful in some cases:
if hasattr(el, '__iter__'):
This covers
On Tue, 2009-05-05 at 12:15 -0400, J Kenneth King wrote:
Emile van Sebille em...@fenx.com writes:
On 5/1/2009 7:31 AM J Kenneth King said...
Chris Rebert c...@rebertia.com writes:
b = []
for pair in a:
for item in pair:
b.append(item)
This is much more clear than a
namekuseijin wrote:
On May 4, 9:15 am, David Robinow drobi...@gmail.com wrote:
On Mon, May 4, 2009 at 2:33 AM, namekuseijin
namekuseijin.nos...@gmail.com wrote:
ls = [(1,2), (3,4), (5, None), (6,7), (8, None)]
[(x,y) for (x,y) in ls if y]
[(1, 2), (3, 4), (6, 7)]
On Tue, 05 May 2009 13:43:32 -0400, J. Cliff Dyer wrote:
On Fri, 2009-05-01 at 13:00 -0400, John Posner wrote:
Shane Geiger wrote:
if type(el) == list or type(el) is tuple:
A tiny improvement:
if type(el) in (list, tuple):
Another alternative, which might be useful in some
2009/5/5 Ricardo Aráoz ricar...@gmail.com:
This seems to work for any length tuples :
a = [(1,2), (3,4, 'goes'), (5,None), (6,7, 8, 'as', None), (8, None),
(9, 0)]
[tup for tup in a if not [e for e in tup if e == None]]
[(1, 2), (3, 4, 'goes'), (9, 0)]
Why that extra for? KISS
a =
On May 6, 4:01 am, J. Cliff Dyer j...@sdf.lonestar.org wrote:
The way you have to bounce your eyes back and forth in the comprehension
makes it hard to read the logic. With the loop, on the other hand it is
blatantly obvious which way the nesting occurs.
[ item for j in a if len(j)==2 for
On Tue, 05 May 2009 20:36:37 -0700, alex23 wrote:
On May 6, 4:01 am, J. Cliff Dyer j...@sdf.lonestar.org wrote:
The way you have to bounce your eyes back and forth in the
comprehension makes it hard to read the logic. With the loop, on the
other hand it is blatantly obvious which way the
Steven D'Aprano wrote:
On Tue, 05 May 2009 13:43:32 -0400, J. Cliff Dyer wrote:
Except for the ones that it doesn't cover, like strings:
hasattr('abcd', '__iter__')
False
True in Python3
--
http://mail.python.org/mailman/listinfo/python-list
ls = [(1,2), (3,4), (5, None), (6,7), (8, None)]
[(x,y) for (x,y) in ls if y]
[(1, 2), (3, 4), (6, 7)]
--
http://mail.python.org/mailman/listinfo/python-list
Snorri H a.a.ovtchinni...@gmail.com writes:
On May 3, 6:13 am, Ross ross.j...@gmail.com wrote:
I'm trying to set up a simple filter using a list comprehension. If I
have a list of tuples, a = [(1,2), (3,4), (5,None), (6,7), (8, None)]
and I wanted to filter out all tuples containing None, I
On May 3, 6:13 am, Ross ross.j...@gmail.com wrote:
I'm trying to set up a simple filter using a list comprehension. If I
have a list of tuples, a = [(1,2), (3,4), (5,None), (6,7), (8, None)]
and I wanted to filter out all tuples containing None, I would like to
get the new list b = [(1,2),
On Mon, May 4, 2009 at 2:33 AM, namekuseijin
namekuseijin.nos...@gmail.com wrote:
ls = [(1,2), (3,4), (5, None), (6,7), (8, None)]
[(x,y) for (x,y) in ls if y]
[(1, 2), (3, 4), (6, 7)]
Nope. That filters out 0 as well as None. Not what the OP asked for.
--
On May 4, 9:15 am, David Robinow drobi...@gmail.com wrote:
On Mon, May 4, 2009 at 2:33 AM, namekuseijin
namekuseijin.nos...@gmail.com wrote:
ls = [(1,2), (3,4), (5, None), (6,7), (8, None)]
[(x,y) for (x,y) in ls if y]
[(1, 2), (3, 4), (6, 7)]
Nope. That filters out 0 as well as None.
This isn't list comprehension, but it's something to keep in mind:
b = filter(lambda x: None not in x, input_list)
On Sat, May 2, 2009 at 10:25 PM, CTO debat...@gmail.com wrote:
On May 2, 10:13 pm, Ross ross.j...@gmail.com wrote:
I'm trying to set up a simple filter using a list
I'm trying to set up a simple filter using a list comprehension. If I
have a list of tuples, a = [(1,2), (3,4), (5,None), (6,7), (8, None)]
and I wanted to filter out all tuples containing None, I would like to
get the new list b = [(1,2), (3,4),(6,7)].
I tried b = [i for i in a if t for t in i
On Sat, May 2, 2009 at 7:13 PM, Ross ross.j...@gmail.com wrote:
I'm trying to set up a simple filter using a list comprehension. If I
have a list of tuples, a = [(1,2), (3,4), (5,None), (6,7), (8, None)]
and I wanted to filter out all tuples containing None, I would like to
get the new list b
On May 2, 7:21 pm, Chris Rebert c...@rebertia.com wrote:
On Sat, May 2, 2009 at 7:13 PM, Ross ross.j...@gmail.com wrote:
I'm trying to set up a simple filter using a list comprehension. If I
have a list of tuples, a = [(1,2), (3,4), (5,None), (6,7), (8, None)]
and I wanted to filter out all
On May 2, 10:13 pm, Ross ross.j...@gmail.com wrote:
I'm trying to set up a simple filter using a list comprehension. If I
have a list of tuples, a = [(1,2), (3,4), (5,None), (6,7), (8, None)]
and I wanted to filter out all tuples containing None, I would like to
get the new list b = [(1,2),
Ross ross.j...@gmail.com writes:
If I have a list of tuples a = [(1,2), (3,4), (5,6)], and I want to
return a new list of each individual element in these tuples, I can do
it with a nested for loop but when I try to do it using the list
comprehension b = [j for j in i for i in a], my output
On May 1, 2:28 pm, Arnaud Delobelle arno...@googlemail.com wrote:
Ross ross.j...@gmail.com writes:
If I have a list of tuples a = [(1,2), (3,4), (5,6)], and I want to
return a new list of each individual element in these tuples, I can do
it with a nested for loop but when I try to do it
Chris Rebert c...@rebertia.com writes:
On Thu, Apr 30, 2009 at 5:56 PM, Ross ross.j...@gmail.com wrote:
If I have a list of tuples a = [(1,2), (3,4), (5,6)], and I want to
return a new list of each individual element in these tuples, I can do
it with a nested for loop but when I try to do it
On 5/1/2009 7:31 AM J Kenneth King said...
Chris Rebert c...@rebertia.com writes:
b = []
for pair in a:
for item in pair:
b.append(item)
This is much more clear than a nested comprehension.
I love comprehensions, but abusing them can lead to really dense and
difficult to read
Emile van Sebille em...@fenx.com writes:
On 5/1/2009 7:31 AM J Kenneth King said...
Chris Rebert c...@rebertia.com writes:
b = []
for pair in a:
for item in pair:
b.append(item)
This is much more clear than a nested comprehension.
I love comprehensions, but abusing them can
from goopy.functional import flatten #
http://sourceforge.net/projects/goog-goopy/
b = [(1,2), (3,4), (5,6)]
print flatten(b)
#from goopy.functional import flatten #
http://sourceforge.net/projects/goog-goopy/
def flatten(seq):
Returns a list of the contents of seq with sublists and
Shane Geiger wrote:
if type(el) == list or type(el) is tuple:
A tiny improvement:
if type(el) in (list, tuple):
--
http://mail.python.org/mailman/listinfo/python-list
On 5/1/2009 9:19 AM Arnaud Delobelle said...
Emile van Sebille em...@fenx.com writes:
On 5/1/2009 7:31 AM J Kenneth King said...
I love comprehensions, but abusing them can lead to really dense and
difficult to read code.
I disagree on dense and difficult, although I'll leave open the
Emile van Sebille em...@fenx.com writes:
On 5/1/2009 9:19 AM Arnaud Delobelle said...
Emile van Sebille em...@fenx.com writes:
On 5/1/2009 7:31 AM J Kenneth King said...
I love comprehensions, but abusing them can lead to really dense and
difficult to read code.
I disagree on dense and
John Posner wrote:
Shane Geiger wrote:
if type(el) == list or type(el) is tuple:
A tiny improvement:
if type(el) in (list, tuple):
or (even better)
if isinstance(el, (list, tuple))
However, it is my contention that you shouldn't be flattening by type --
you should know where,
If I have a list of tuples a = [(1,2), (3,4), (5,6)], and I want to
return a new list of each individual element in these tuples, I can do
it with a nested for loop but when I try to do it using the list
comprehension b = [j for j in i for i in a], my output is b =
[5,5,5,6,6,6] instead of the
On Thu, Apr 30, 2009 at 5:56 PM, Ross ross.j...@gmail.com wrote:
If I have a list of tuples a = [(1,2), (3,4), (5,6)], and I want to
return a new list of each individual element in these tuples, I can do
it with a nested for loop but when I try to do it using the list
comprehension b = [j for
Ross wrote:
If I have a list of tuples a = [(1,2), (3,4), (5,6)], and I want to
return a new list of each individual element in these tuples, I can do
it with a nested for loop but when I try to do it using the list
comprehension b = [j for j in i for i in a], my output is b =
[5,5,5,6,6,6]
Hi,
Im new to python, and OOP, and am trying to get a handle on list
comprehension.
Say I have a class Foo with a property called bar:
class Foo:
def __init__(self):
self.bar = random.randint(1,100)
and then I make a list of these objects:
Newlist = []
for x in range(10):
Dr Mephesto wrote:
Hi,
Im new to python, and OOP, and am trying to get a handle on list
comprehension.
Say I have a class Foo with a property called bar:
class Foo:
def __init__(self):
self.bar = random.randint(1,100)
and then I make a list of these objects:
Newlist =
Dr Mephesto wrote:
Hi,
Im new to python, and OOP, and am trying to get a handle on list
comprehension.
Say I have a class Foo with a property called bar:
class Foo:
def __init__(self):
self.bar = random.randint(1,100)
and then I make a list of these objects:
Newlist = []
for x in
On Jan 21, 2009, at 10:52 AM, Dr Mephesto wrote:
Hi,
Im new to python, and OOP, and am trying to get a handle on list
comprehension.
Say I have a class Foo with a property called bar:
class Foo:
def __init__(self):
self.bar = random.randint(1,100)
and then I make a list of these
Diez B. Roggisch wrote:
Dr Mephesto wrote:
Hi,
Im new to python, and OOP, and am trying to get a handle on list
comprehension.
Say I have a class Foo with a property called bar:
class Foo:
def __init__(self):
self.bar = random.randint(1,100)
and then I make a list of these
In article mailman.7691.1232554737.3487.python-l...@python.org,
Philip Semanchuk phi...@semanchuk.com wrote:
Other answers have been good; to them I'll add the comment that list
comprehensions are for *constructing* lists, not manipulating the
elements thereof.
HTH
Philip
Well
Lou Pecora wrote:
In article mailman.7691.1232554737.3487.python-l...@python.org,
Philip Semanchuk phi...@semanchuk.com wrote:
Other answers have been good; to them I'll add the comment that list
comprehensions are for *constructing* lists, not manipulating the
elements thereof.
HTH
On Jan 21, 2009, at 11:52 AM, Lou Pecora wrote:
In article mailman.7691.1232554737.3487.python-l...@python.org,
Philip Semanchuk phi...@semanchuk.com wrote:
Other answers have been good; to them I'll add the comment that list
comprehensions are for *constructing* lists, not manipulating the
Dr Mephesto wrote:
Hi,
Im new to python, and OOP, and am trying to get a handle on list
comprehension.
Say I have a class Foo with a property called bar:
class Foo:
def __init__(self):
self.bar = random.randint(1,100)
and then I make a list of these objects:
Newlist = []
for x in
MRAB schrieb:
Diez B. Roggisch wrote:
Dr Mephesto wrote:
Hi,
Im new to python, and OOP, and am trying to get a handle on list
comprehension.
Say I have a class Foo with a property called bar:
class Foo:
def __init__(self):
self.bar = random.randint(1,100)
and then I make a list
You can try this
import random
class foo:
def __init__(self):
self.bar = random.randint(1,100)
def getbar(ls,i):
ls.append(foo())
ls[i].bar = ls[i].bar * 3
ls = []
[getbar(ls,i) for i in range(10)]
On Thu, Jan 22, 2009 at 4:45 AM, Diez B. Roggisch de...@nospam.web.dewrote:
On Aug 24, 5:35 am, Boris Borcic [EMAIL PROTECTED] wrote:
Paul Rubin wrote:
beginner [EMAIL PROTECTED] writes:
For example, if I have x=[ [1,2], [3,4] ]
What I want is a new list of list that has four sub-lists:
[[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]]
[[a, map(f,a)] for a in x]
beginner [EMAIL PROTECTED] writes:
For example, if I have x=[ [1,2], [3,4] ]
What I want is a new list of list that has four sub-lists:
[[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]]
[[a, map(f,a)] for a in x]
--
http://mail.python.org/mailman/listinfo/python-list
Boris Borcic [EMAIL PROTECTED] writes:
For example, if I have x=[ [1,2], [3,4] ]
What I want is a new list of list that has four sub-lists:
[[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]]
[[a, map(f,a)] for a in x]
no, that one will be [[[1,2], [f(1), f(2)]], [[3,4], [f(3), f(4)]]]
eg
Paul Rubin wrote:
beginner [EMAIL PROTECTED] writes:
For example, if I have x=[ [1,2], [3,4] ]
What I want is a new list of list that has four sub-lists:
[[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]]
[[a, map(f,a)] for a in x]
no, that one will be [[[1,2], [f(1), f(2)]], [[3,4], [f(3),
On Aug 24, 12:44 am, beginner [EMAIL PROTECTED] wrote:
On Aug 24, 12:41 am, Davo [EMAIL PROTECTED] wrote:
On Aug 23, 9:24 pm, beginner [EMAIL PROTECTED] wrote:
Hi All,
How do I map a list to two lists with list comprehension?
For example, if I have x=[ [1,2], [3,4] ]
What I
On Aug 24, 5:47 am, Paul Rubin http://[EMAIL PROTECTED] wrote:
Boris Borcic [EMAIL PROTECTED] writes:
For example, if I have x=[ [1,2], [3,4] ]
What I want is a new list of list that has four sub-lists:
[[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]]
[[a, map(f,a)] for a in x]
no,
Boris Borcic wrote:
For example, if I have x=[ [1,2], [3,4] ]
What I want is a new list of list that has four sub-lists:
[[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]]
[[a, map(f,a)] for a in x]
[map(g,a) for a in x for g in [None,f]]
will do it.
...a bit too cleverly, but there's worse :
For example, if I have x=[ [1,2], [3,4] ]
What I want is a new list of list that has four sub-lists:
[[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]]
[[a, [f(b) for b in a]] for a in x]
--
http://mail.python.org/mailman/listinfo/python-list
Hi All,
How do I map a list to two lists with list comprehension?
For example, if I have x=[ [1,2], [3,4] ]
What I want is a new list of list that has four sub-lists:
[[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]]
[1,2] is mapped to [1,2] and [f(1), f(2)] and [3,4] is mapped to
[3,4], [f(3),
On Aug 23, 9:24 pm, beginner [EMAIL PROTECTED] wrote:
Hi All,
How do I map a list to two lists with list comprehension?
For example, if I have x=[ [1,2], [3,4] ]
What I want is a new list of list that has four sub-lists:
[[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]]
[1,2] is mapped to
beginner wrote:
How do I map a list to two lists with list comprehension?
For example, if I have x=[ [1,2], [3,4] ]
What I want is a new list of list that has four sub-lists:
[[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]]
[1,2] is mapped to [1,2] and [f(1), f(2)] and [3,4] is mapped to
On Aug 24, 12:41 am, Davo [EMAIL PROTECTED] wrote:
On Aug 23, 9:24 pm, beginner [EMAIL PROTECTED] wrote:
Hi All,
How do I map a list to two lists with list comprehension?
For example, if I have x=[ [1,2], [3,4] ]
What I want is a new list of list that has four sub-lists:
On Aug 23, 9:24 pm, beginner [EMAIL PROTECTED] wrote:
Hi All,
How do I map a list to two lists with list comprehension?
For example, if I have x=[ [1,2], [3,4] ]
What I want is a new list of list that has four sub-lists:
[[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]]
[1,2] is mapped to
96 matches
Mail list logo