Mainly Tech projects on Python and Electronic Design Automation.

Wednesday, February 06, 2008

Python tuples and lists

Just my attempt at explaining lists w.r.t. tuples, after href="http://news.e-scribe.com/397">this post.

With a tuple, the value and type of items at each index of a
tuple may have significance, but successive items in a tuple rarely
have similar meanings.

With lists, successive items usually have similar meanings.



(Big analogy time): cars on a motorway might be modelled as a list of
car objects, but a car might be modelled as a tuple as the constituents
of a car might be treated differently:

  style="font-family: monospace;"> style="font-weight: bold; color: rgb(255, 0, 0);">(engine,
seats, wheels, colour, valid_tax, speed,  lights_on ,... style="font-weight: bold; color: rgb(255, 0, 0);">)



 wheras each car on a motorway might be treated in a similar
way:

style="font-family: monospace;">pull_over( car for cars in style="font-weight: bold; color: rgb(255, 0, 0);">[car1,
car2, ...] if not car[valid_tax_index style="font-weight: bold; color: rgb(255, 0, 0);">])




- Paddy.

No comments:

Post a Comment

Followers

Subscribe Now: google

Add to Google Reader or Homepage

Go deh too!

whos.amung.us

Blog Archive