kuroko/test/testGeneratorExpressions.krk

18 lines
507 B
Python
Raw Normal View History

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))))
print('generator object' in str((x * x for x in range(10))))
# Should be directly usable as function argument
2021-03-08 10:36:12 +03:00
print(sum(x * x for x in range(10)))
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)')
except SyntaxError as e:
print('parenthesized' in str(e))
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))