Beginner help

breamoreboy at gmail.com breamoreboy at gmail.com
Sun Feb 5 19:12:47 EST 2017


On Sunday, February 5, 2017 at 11:27:19 PM UTC, pha... at u.rochester.edu wrote:
> Hi everyone. I'm new to python and have hit a bit of a wall with an assignment I'm working on. I created a number of classes and instantiated them, now I need to create a list out of them. I am looking for something more elegant than appending each object to the list as I instantiate it. I tried setting up an if loop, but didn't get far with it. Any suggestions?

If loop, for heavens sake :)

Try one of these beasties instead https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions

Kindest regards.

Mark Lawrence.



More information about the Python-list mailing list