Generator Expressions : zip « Buildin Function « Python






Generator Expressions

Generator Expressions
sum(i*i for i in range(10))                 # sum of squares

xvec = [10, 20, 30]
yvec = [7, 5, 3]

print sum(x*y for x,y in zip(xvec, yvec))         # dot product

           
       








Related examples in the same category

1.Loop over two or more sequences at the same timeLoop over two or more sequences at the same time
2.Zip a two listsZip a two lists
3.Read element in a zipped listRead element in a zipped list
4.Zip three tuplesZip three tuples
5.Difference between zip and mapDifference between zip and map
6.Zip function demo: returns a list of tuplesZip function demo:  returns a list of tuples