Skip to content

Instantly share code, notes, and snippets.

@sixthgear
Forked from mjard/gist:3137490
Created July 18, 2012 17:19
Show Gist options
  • Save sixthgear/3137564 to your computer and use it in GitHub Desktop.
Save sixthgear/3137564 to your computer and use it in GitHub Desktop.
#sixthgear, one-up me willya
map = lambda s,f: __builtins__.map(f,s)
# kaptin, safe from desg
def map(source, func):
return __builtins__.map(func, source)
# sixthgear
def mop(source, func):
return map(func, source)
# pythonic
def map(source, func):
dest = []
for x in source:
dest.append(func(x))
return dest
# list comprehension
def map(source, func):
return [func(x) for x in source]
# lambda
map = lambda s,f: [f(x) for x in s]
# generator
def map(source, func):
for x in source:
yield func(x)
# desg
def map(list,func):
x = 0
for len(list) in x:
new_list = new_list.append(func(list[x]))
x += 1
return new_list
# desg that works
def map(source, func):
dest = list() # this is why we don't name things list
for i, x in enumerate(source):
dest.append(func(source[i]))
return dest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment