-
Notifications
You must be signed in to change notification settings - Fork 27
Challenge solved with lambdas #7
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
base: master
Are you sure you want to change the base?
Conversation
hyfi06
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments
challenge.py
Outdated
| ] | ||
|
|
||
| def homeless(worker): | ||
| worker['homeless'] = True if worker['organization'] == '' else False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worker['organization'] == '' ya es un booleano
worker['homeless'] = worker['organization'] == ''
challenge.py
Outdated
|
|
||
| def run(): | ||
| def older_than_30(person): | ||
| person['old'] = True if person['age'] >30 else False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
person['age'] >30 ya es booleano
person['old'] = person['age'] >30| }, | ||
| ] | ||
|
|
||
| def homeless(worker): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aquí pasa pasa un diccionario por referencia, por lo que estás modificando DATA directamente. tienes que crear un nuevo diccionario y luego modificarlo.
new_worker = dict(worker)| return worker | ||
|
|
||
| def run(): | ||
| def older_than_30(person): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recuerda que los diccionarios pasan por referencia. Tienes que crear uno nuevo para no modificar el original.
| all_Platzi_workers = list(filter(lambda x: x['organization']=='Platzi',DATA))# Using filter, generate a list with all the Platzi workers | ||
| adults = list(filter(lambda x: x['age']>18,DATA))# Using filter, generate a list with all people over 18 years old | ||
| workers = list(map(homeless, DATA)) # 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 = list(map(older_than_30, DATA)) # 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vas a notar que al imprimir old_people tienes también la información de homeless, por que se modificó DATA en la línea anterior.
| all_python_devs = list(filter(lambda x: x['language']=='python',DATA)) # Using filter, generate a list with all the python devs | ||
| all_Platzi_workers = list(filter(lambda x: x['organization']=='Platzi',DATA))# Using filter, generate a list with all the Platzi workers | ||
| adults = list(filter(lambda x: x['age']>18,DATA))# Using filter, generate a list with all people over 18 years old |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bien!
Ya hice los cambios, muchas gracias! 👍 |
hyfi06
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
No description provided.