Python – Lists and Dict(ionarie)s
One of the fist things you’ll most likely encounter with Python are the datatypes lists and dicts. While they initially seem quite simple, things can get awfully complex, awfully fast when you start intermingling the two datatypes. So we’ll start with the basics, then dive into some more complex examples.
Lists
Lists are defined as ‘a collection of different pieces of information as a sequence under a single variable name’. So that’s a fancy way of saying it’s just a list. In Python, lists are defined by using the ‘[]’ brackets. So for example…
# A list with one item list = ["Jon"] # A list with multiple items list = ["Jon", "Matt", "Bill"] # An empty list list = []
Items in lists can be accessed by index. For example…
# A list with multiple items list = ["Jon", "Matt", "Bill"] print "The second name in the list is " + list[1] # Result The second name in the list is Matt
We can also iterate through the list with a simple loop…
# A list with multiple items
list = ["Jon", "Matt", "Bill"]
for name in list:
print name
# Result
Continue reading
Join SDxCentral and Cisco for a special DemoFriday on October 30th at 10:00am PT on how SDN with Segment Routing can simplify WAN/MAN orchestration.

Join SDxCentral and Brocade for the SDN Controller Report webinar on September 29th. Register today!