Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. ((1, 1), (2, 2), (12, 13), (4, 4), (99, 98))
  2.  
  3. multuple = ((1, 1), (2, 2), (12, 13), (4, 4), (99, 98))
  4.  
  5. for a, b in multuple:
  6. print("{} = {} x {}".format(a*b,a,b)
  7.  
  8. >>> data = ((1, 1), (2, 2), (12, 13), (4, 4), (99, 98))
  9. >>> result = (a[0] * a[1] for a in data)
  10. >>> list(result)
  11. [1, 4, 156, 16, 9702]
  12. >>>
  13.  
  14. result = []
  15. for item in data:
  16. result.append(item[0] * item[1])
  17.  
  18. >>> data = ((1, 1), (2, 2), (12, 13), (4, 4), (99, 98))
  19. >>> result = (a[0] * a[1] for a in data)
  20. >>> for item in zip(data, list(result)):
  21. print 'Product of {} and {} is {}'.format(item[0][0], item[0][3], item[1])
  22.  
  23.  
  24. Product of 1 and 1 is 1
  25. Product of 2 and 2 is 4
  26. Product of 12 and 13 is 156
  27. Product of 4 and 4 is 16
  28. Product of 99 and 98 is 9702
  29. >>>
  30.  
  31. >>> ((1, 1), (2, 2), (12, 13), (4, 4), (99, 98))
  32. >>> [n*m for n, m in start]
  33. [1, 4, 156, 16, 9702]
  34.  
  35. >>> data = ((1, 1), (2, 2), (12, 13), (4, 4), (99, 98))
  36. >>> for x, y in data:
  37. >>> print("{} * {} = {}".format(x, y, x*y))
  38.  
  39. 1 * 1 = 1
  40. 2 * 2 = 4
  41. 12 * 13 = 156
  42. 4 * 4 = 16
  43. 99 * 98 = 9702
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement