In this notebook, you will review the additional python syntax we've covered since the first review of fundamentals. You should be able to correctly predict what happens in all of these cases. If you get something wrong, figure out why!
my_list = ['spam']
print len(my_list), len(my_list[0])
print range(10)[-5:]
import random
my_list = ['a','b','c']*3 + ['c','d','e']*3
random.shuffle(my_list)
my_list[0:5]
import random
my_list = ['a','b','c'] + ['c','d','e']
random.sample(my_list,7)
import random
[round(random.random(),1) for i in range(15)]
vowels = ['a', 'e', 'i','o','u']
print [element*i for i,element in enumerate(vowels)]
print ' '.join([' '.join((i, 'and a')) for i in ('one', 'two', 'three', 'four')])
responses = 'ccctcttcttttcccttctcccctctctccc'
[i for i,curResp in enumerate(responses) if curResp=='c']
import random
positions = ['left', 'middle', 'right']
positions2 = positions
positions.append('bottom')
random.shuffle(positions2)
print positions, positions2
print len(positions), len(positions2)
print positions==positions2
positions = {'left':(-100,0), 'middle':(0,0), 'right':(100,0)}
[random.choice(positions.keys()) for i in range(10)]
positions = {'left':(-100,0), 'middle':(0,0), 'right':(100,0)}
[positions[random.choice(positions.keys())] for i in range(10)]
responses = 'ccctcttcttttcccttctcccctctctccc'
responsesMapping = {'c':'chair','t':'table'}
[responsesMapping[curResp] for curResp in responses]