2021-03-08 10:36:12 +03:00
|
|
|
print(sum([x * x for x in range(10)]))
|
|
|
|
print(sum((x * x for x in range(10))))
|
2021-03-06 05:13:49 +03:00
|
|
|
|
|
|
|
print('generator object' in str((x * x for x in range(10))))
|
2021-03-06 05:19:34 +03:00
|
|
|
|
|
|
|
# Should be directly usable as function argument
|
2021-03-08 10:36:12 +03:00
|
|
|
print(sum(x * x for x in range(10)))
|
2021-03-06 05:19:34 +03:00
|
|
|
|
|
|
|
import dis
|
|
|
|
# Should have a compile error:
|
|
|
|
try:
|
2021-03-08 10:36:12 +03:00
|
|
|
dis.build('sum(x * x for x in range(10), 2, 3)')
|
2021-03-06 05:19:34 +03:00
|
|
|
except SyntaxError as e:
|
|
|
|
print('parenthesized' in str(e))
|
|
|
|
|
2021-03-06 09:32:30 +03:00
|
|
|
let matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
|
|
|
|
print(list(entry for row in matrix for entry in row))
|