Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Se desarrollan funciones lamnda y se da solución al reto. #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ venv/
ENV/
env.bak/
venv.bak/

reto07/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unas el nombre convencional de ENV para tu entorno, como vez está arriba ignorado.

# Spyder project settings
.spyderproject
.spyproject
Expand Down
20 changes: 10 additions & 10 deletions challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,35 @@

def run():

all_python_devs = # Using filter, generate a list with all the python devs
all_Platzi_workers = # Using filter, generate a list with all the Platzi workers
adults = # Using filter, generate a list with all people over 18 years old
workers = # Using map, generate a new list of people with a key 'homeless' with True or False values, if 'organization' have something or not
old_people = # Using map, generate a new list of people with a key 'old' with True or False values, if 'age' is greater than 30 or not
all_python_devs = filter(lambda x : x['language'] == 'python', DATA)
all_Platzi_workers = filter(lambda x : x['organization'] == 'Platzi', DATA)
adults = filter(lambda x : x['age'] > 18, DATA)
Comment on lines +77 to +79
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bien!

workers = list(map(lambda x: dict(x, **{'Homeless':True}) if x['organization'] == '' else dict(x, **{'Homeless':False}), DATA))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prioriza que tu código sea entendible sobre que sera corto. DRY! dict(x, **{'Homeless':True}) esto está dos veces, una mejora sería:

list(map( lambda x: dict(x, **{'homeless': True if x['organization'] == '' else False }), DATA))

Pero no requieres el if, por que x['organization'] == '' ya es booleano.

list(map( lambda x: dict(x, **{'homeless': x['organization'] == '' }), DATA))

old_people = list(map(lambda x: dict(x, **{'old':True}) if x['age'] > 30 else dict(x, **{'Old':False}), DATA))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list(map(lambda x: dict(x, **{'old': x['age'] > 30 }), DATA))


print('Python devs: ')

for dev in all_python_devs:
print(dev['name'])
print('\n\n')

print('Platzi workers: ')
for worker in all_Platzi_workers:
print(worker['name'])
print('\n\n')

print('Adults: ')
for adult in adults:
print(adult['name'])
print('\n\n')

print(workers)
print('\n\n')



print(old_people)
print('\n\n')

# Remember: when possible, use lambdas


if __name__ == '__main__':
run()
1 change: 1 addition & 0 deletions lambdas.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import requests
import json

Expand Down