import datetime
Dictionary
Dictionary is used when there exists a mapping relationship, for example, in stock market data, stock prices are linked to a specific date.
stock = {"Header":["Open","High","Low","Close"],"12/12/2015":[32.03,50,40,32]}
stock["12/12/2015"]
Dictionary provides some useful methods
list(stock.iterkeys()) #key iterator, giving you a list
list(stock.iteritems()) #iterm iterator, giving you tuples, representing relations
Dictionary can also be feeded in the constructor of pandas dataframe. We will talk about this in my later posts.
Tuple
Anything you want to be considered as a whole should use turple becuase it’s immutable. Turple often used in feeding a set of arguments into function caller.
x=12
y=23
z=23.6
point = (x,y,z) # a coordinate can use turple to replesent because the
# position of each element matters
Some people also argues that you can compare tuple to strcut in C/C++ since tuple usually holds heterogeneous collections.
As I mentioned, tuple also used to represent relations in discrete data structure. I can use you an example using dictionary and tuple
# for example, we have y = x^2
f = {1:1,2:4,3:9}
f.items() # the items method can turn dictionary into a tuple
List
List is like array in other programming language. You should use list in situations that uses array. In python, list provides you more methods to perform comprehensive analysis.
List as stack operation
l = []
l.append(1)
l.append(2)
l.append(3)
l
l.pop() # First in first out
l
l.append(4)
l
l.pop()
l.pop()
l
List sorting
l = [2,3,9,4]
l.sort()
l
List Reversing
l.reverse()
l
List Extend Method
l.extend([1]) # need to feed a list, and will insert the element to a proper place
l
Other List Methods
l.remove(1) #remove elements
l
l.index(4) # return the position of an element
l.insert(0,2) # insert 2 into index 0
l
We will talk about data structure usage more in-depth later in my blog when we go further into analysis.