Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79372
| Date | 2014-10-21 00:40 -0700 |
|---|---|
| From | Larry Hudson <orgnut@yahoo.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Building lists |
| References | <obja4a5ij57rtuaivtvcuqsufhuhk3a2su@4ax.com> <mailman.15001.1413834029.18130.python-list@python.org> <6jpa4ahhc8ln7hk8s0258hvqd3io51epa0@4ax.com> |
| Message-ID | <bsydndqKI9xKkNvJnZ2dnUU7-e-dnZ2d@giganews.com> (permalink) |
On 10/20/2014 12:49 PM, Seymore4Head wrote:
> On Mon, 20 Oct 2014 20:40:18 +0100, MRAB <python@mrabarnett.plus.com>
> wrote:
>
<snip>
> Do you have to know the number of items the list will have before
> making it?
>
No. Lists are NOT the same as arrays in other languages. But it IS possible to create an
initial list of a specific size:
myList = [None] * 50
This creates a 50-element list with each element set to None. (BTW, that makes the indexes
0-49, not 0-50.) I have occasionally found this useful, but I emphasize it is only RARELY
useful. The .append() method is far more versatile.
As to your original problem: my question to you is what is your purpose?
1) To solve this particular problem, using Python.
or
2) To explore the usage of lists by applying them to this problem.
If your purpose is the first, then I agree with the advice you have already been given here --
dictionaries are a much better fit to this problem.
If your purpose is the second, then go ahead, have at it. But realize that to more experienced
Pythonistas this approach the very un-pythonic for this problem. It would be even better to try
multiple approaches -- lists, dictionaries, lists with dictionaries, dictionaries with lists or
tuples... or whatever combination you can come up with. This will give you even more
experience and allow you to evaluate these various techniques.
And no, I won't give you a ready-made "canned" answer. For one thing your original description
is much too vague. But good luck!
-=- Larry -=-
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 14:10 -0400
Re: Building lists sohcahtoa82@gmail.com - 2014-10-20 11:18 -0700
Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 14:21 -0400
Re: Building lists sohcahtoa82@gmail.com - 2014-10-20 11:33 -0700
Re: Building lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-20 20:55 +0100
Re: Building lists MRAB <python@mrabarnett.plus.com> - 2014-10-20 20:40 +0100
Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 15:49 -0400
Re: Building lists Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-20 13:58 -0600
Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 16:23 -0400
Re: Building lists Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-20 14:45 -0600
Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 16:55 -0400
Re: Building lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-20 21:47 +0100
Re: Building lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-20 20:57 +0100
Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 16:24 -0400
Re: Building lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-20 22:40 +0000
Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 18:44 -0400
Re: Building lists Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-21 10:55 +1100
Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 20:05 -0400
Re: Building lists Larry Hudson <orgnut@yahoo.com> - 2014-10-21 00:11 -0700
Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-21 08:54 -0400
Re: Building lists Larry Hudson <orgnut@yahoo.com> - 2014-10-21 00:40 -0700
Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-21 08:55 -0400
Re: Building lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-20 22:30 +0000
Re: Building lists MRAB <python@mrabarnett.plus.com> - 2014-10-20 23:57 +0100
Re: Building lists John Gordon <gordon@panix.com> - 2014-10-20 20:48 +0000
Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 17:25 -0400
Re: Building lists Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-20 15:34 -0600
Re: Building lists Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-20 21:31 -0400
Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-21 08:55 -0400
Re: Building lists Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-10-21 10:54 +1300
Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 17:57 -0400
Re: Building lists Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-20 21:27 -0400
csiph-web