Ask Your Question

Revision history [back]

Hello,

In Python (and hence Sage) you have very useful list comprehension

sage: my_list = [1, 2, 3, 4]
sage: [2^i for i in my_list] 
[2, 4, 8, 16]

If you use vectors, you can alternatively do

sage: v = vector([1, 2, 3, 4])
sage: v.apply_map(lambda x: 2^x)
(2, 4, 8, 16)

Vincent