Day 88, Python 101s

More interviews.

Some basic Python

# list comprehension
[x for x in range(9) if x%3 == 0]

# sum an array of numbers
# lazy version
arr = range(9)
sum(arr)

# naive version
sum = 0
for x in arr:
  sum += x

# reduce version
reduce( (lambda x,y : x+y ), range(9) )

Advertisements
Standard