'''ds.py demonstrates some common Data Structures ''' from __future__ import print_function from collections import deque import functools ''' The following lines demonstrtae how a list works in Python and some common list functions ''' list = [] # creates an empty list print(list) list = [10, 14.5, "Spongebob"] #lists can contain multiple kinds of data print(list) list = [x**2 for x in range(0,19)] ''' A list can be populated using list comprehensions, where we generate a series of numbers uingg a loop, inside the list notation ''' print(list) list2 =[10,20,30,40] ; list1 = [] list1.append("Krabby Patty") # append adds the item to the end of the list print(list2) print(list2[3], list2.index(10)) # We can query for a value using the index and # query for the index using the value list2 = [x*3 for x in range(0,20)] #another list comprehension ''' The following lines show how to slide and slice on a list ''' print(list2[3:15]) # prints list elemets 3 through 15 print(list2[14:]) # element 14 until the end print(list2[:5]) # from the beginning until element 5 print(list2[:]) # all of it print(list[12:19:2]) # from element 2 until 19, step size 2 print(list2[-1]) #last element print(list2[-2:]) # print(list2[:-2]) ''' stack = [12, 42, -87, 0, 3.5] stack.append(91) print(stack) print(stack.pop()) print(stack) queue = deque([12,19, 8, 15, 25]) queue.append(150) print(queue) print(queue.popleft()) print(queue) list3 = [5,2,-10,19,34, 6, 99,0] list3.sort() list3.reverse() print(list3) string = ['x', 'Y', 'a', 'A', 'k'] string.sort() print(string) string.sort(cmp = lambda a,b : cmp(a.lower(), b.lower())) print(string) string2 = ['g', 'M', '0', 'Y', 'a'] string2.sort(key = str.lower) print(string2) myset = set() alsoset = set([]) print(myset) print(alsoset) myset = set([1,2,5,7,0]) alsoset = {x/2 for x in range(0,10)} print(myset) print(alsoset)