fork download
  1. def expensive_function(x):
  2. print("called the very expensive function, that will be $2")
  3. return x*x + x
  4.  
  5. data = [4, 7, 3, 7, 2, 3, 4, 7, 3, 1, 1 ,1]
  6.  
  7.  
  8. result = [
  9. (x, expensive)
  10. for x in data
  11. for expensive in [expensive_function(x)] #alias
  12. if expensive > 3
  13. ]
  14.  
  15. print(result)
Success #stdin #stdout 0.04s 9984KB
stdin
Standard input is empty
stdout
called the very expensive function, that will be $2
called the very expensive function, that will be $2
called the very expensive function, that will be $2
called the very expensive function, that will be $2
called the very expensive function, that will be $2
called the very expensive function, that will be $2
called the very expensive function, that will be $2
called the very expensive function, that will be $2
called the very expensive function, that will be $2
called the very expensive function, that will be $2
called the very expensive function, that will be $2
called the very expensive function, that will be $2
[(4, 20), (7, 56), (3, 12), (7, 56), (2, 6), (3, 12), (4, 20), (7, 56), (3, 12)]