# File: ChapterLists/listproduct.py def innerProd(v1,v2): # v1,v2 vectors res = [] #initialize result for i in range(len(v1)): res.append(v1[i] * v2[i]) return res def main(): print(innerProd([1,2,3],[1,0,1])) #[1,0,3] L1 = ['one', 'two'] L2 = ['a', 'b' ] # ['one a', 'one b', 'two a', 'two b'] print( L1, L2, [x + " " + y for x in L1 for y in L2 ]) #[['one', 'a'], ['one', 'b'], ['two', 'a'], ['two', 'b']] print([ [x,y] for x in L1 for y in L2 ]) # [0, 0, 0, 0, 1, 2, 0, 2, 4] print( [x * y for x in range(3) for y in range(3) ]) # ['a', 'b', 'aa', 'bb'] print( [x * y for x in [1,2] for y in ['a','b'] ] ) # ['ra', 'rb', 'sa', 'sb'] print([x + y for x in ['r','s'] for y in ['a','b'] ]) # ['exann', 'exben'] print( ['ex' + y for y in ['ann','ben'] ] ) main()