Skip to content

Instantly share code, notes, and snippets.

@ppeeou
Created July 5, 2017 00:34
Show Gist options
  • Save ppeeou/214623a37dc177ebd91dea2483a9edcd to your computer and use it in GitHub Desktop.
Save ppeeou/214623a37dc177ebd91dea2483a9edcd to your computer and use it in GitHub Desktop.
python map,filter,each
def _each(list, iter):
for i in range(len(list)):
iter(list[i], i)
def _map(list, iter):
new_list = []
_each(list, lambda v, i: new_list.append(iter(v)))
return new_list
def _filter(list, iter):
new_list = []
_each(list, lambda v, i:
iter(v) and
new_list.append(v))
return new_list
class User:
def __init__(self, id, name, age):
self.id = id
self.name = name
self.age = age
def __str__(self):
return str(self.id) + str(self.name)+ str(self.age)
users = [
User(1, 'ID', 32),
User(2, 'HA', 25),
User(3, 'BJ', 67),
User(4, 'PJ', 12),
User(5, 'JE', 44),
User(6, 'JM', 23)
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment