using push for comprehension results so that it works with object keys, and adding a test for object comprehensions

This commit is contained in:
Jeremy Ashkenas
2009-12-31 15:03:32 -05:00
parent 00538bd62c
commit 07d0044718
4 changed files with 11 additions and 9 deletions

View File

@@ -1,8 +1,12 @@
nums: n * n for n in [1, 2, 3] when n % 2 isnt 0
results: n * 2 for n in nums
obj: {one: 1, two: 2, three: 3}
names: key + '!' for value, key in obj
# next: for n in [1, 2, 3] if n % 2 isnt 0
# print('hi') if false
# n * n * 2
print(results.join(',') is '2,18')
print(results.join(',') is '2,18')
print(names.join(' ') is "one! two! three!")