Re: quick beginners List comprehension question

2009-01-21 Thread Srinivasa NL
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 wrote: > MRAB schrieb: > >> D

Re: quick beginners List comprehension question

2009-01-21 Thread Diez B. Roggisch
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

Re: quick beginners List comprehension question

2009-01-21 Thread Terry Reedy
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

Re: quick beginners List comprehension question

2009-01-21 Thread Philip Semanchuk
On Jan 21, 2009, at 11:52 AM, Lou Pecora wrote: In article , Philip Semanchuk 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 this seems to work just fine. Wh

Re: quick beginners List comprehension question

2009-01-21 Thread Steve Holden
Lou Pecora wrote: > In article , > Philip Semanchuk 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 this seems to work just fine. What

Re: quick beginners List comprehension question

2009-01-21 Thread Lou Pecora
In article , Philip Semanchuk 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 this seems to work just fine. What am I missing: A=[1,2,3] p

Re: quick beginners List comprehension question

2009-01-21 Thread MRAB
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 object

Re: quick beginners List comprehension question

2009-01-21 Thread Philip Semanchuk
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 ob

Re: quick beginners List comprehension question

2009-01-21 Thread MRAB
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

Re: quick beginners List comprehension question

2009-01-21 Thread Diez B. Roggisch
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: >