Skip to content
Open
Changes from 1 commit
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
19 changes: 13 additions & 6 deletions challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,22 @@
},
]

def homeless(worker):
Copy link
Copy Markdown

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)

worker['homeless'] = True if worker['organization'] == '' else False
Copy link
Copy Markdown

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'] == ''

return worker

def run():
def older_than_30(person):
Copy link
Copy Markdown

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.

person['old'] = True if person['age'] >30 else False
Copy link
Copy Markdown

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

return person

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
def run():

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
Comment on lines +86 to +88
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bien!

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
Copy link
Copy Markdown

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.


print('Python devs: ')
for dev in all_python_devs:
print(dev['name'])
Expand Down