Comprehensions
List comprehension
Lists can be comprehended with for
and in
, but, unlike python, conditions can not be used in list comprehension.
foo = [1, 2, 3]
bar = [a ** 2 for a in foo]
return bar == [1, 4, 9] # True
This should effectively be used as a map
function, since sneq does not include map
.
Dictionary comprehension
Dictionaries can be comprehended from lists with for
and in
, but, unlike python, conditions can not be used in list comprehension.
foo = { 'chunky': 'ice cream' }
bar = { k + ' monkey' : v + ' cone' for k, v in foo }
return bar == { 'chunky monkey': 'ice cream cone' } # True
When iterating over a list, the list index will be the first argument and the value will be the second argument.
foo_bar = ["foo", "bar"]
expect = {
'foo0': 'test0',
'bar1': 'test1',
}
val = { car+str(idx): "test"+str(idx) for idx, car in foo_bar }
return val == expect # True