![]() |
Clarification Nested Lists
Hello, I was reading Python Essential Reference by Beazley. It had the following example on nested lists
Quote: a = [1,”Dave”,3.14, [“Mark”, 7, 9, [100,101]], 10] a[1] # Retruns Dave a[3][2] # Returns 9 a[3][3][1] # Returns 101 I just need to confirm something I am having trouble clarifying with the other docs I have found - I think maybe its too simple a question. Could I reference 7 above with a[4] as well as a[3][1]? So again referring to the above example of a[3][3][1] returns 101 why couldn't it be referenced as a[6][1] or do I need a new [] to represent each nest in the list? Finally could I negative reference a[-1] to equal 101 or does this create too much confusion ? |
Quote:
:
To get to box b, one must first open the relevant compartment of box a (in programming terms, that's what a[3] does). To get to box c, one must first open the relevant compartment of box b (which is b[3], or a[3][3], since a[3] is just another way of getting b). Does that make it clearer? Quote:
|
Thanks Arevos, thanks for the reply and clearing that up for me. I thought thats what it was but you know sometimes the simple things trip you up and can be the hardest things to find answers too.
Thanks Again fleb |
Just a small tip, python's interpreter has an interactive mode which you can use to get some hands-on experience with the basics of the language. Just run "python" on the command line.
I can recommend IPython as an "interactive python on steroids". :-) |
| All times are GMT -5. The time now is 1:13 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC