Skip to content

Práctica de list & loops in python #132

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

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
Done till 13.4, tomorrow we will start with 14
  • Loading branch information
danderi committed Nov 13, 2024
commit ea514a9115db073a964204a7eb41f4b59c5d4062
9 changes: 9 additions & 0 deletions .learn/resets/12-Map_a_list/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
celsius_values = [-2, 34, 56, -10]

def celsius_to_fahrenheit(celsius):
# The magic happens here


result = list(map(celsius_to_fahrenheit, celsius_values))

print(result)
5 changes: 5 additions & 0 deletions .learn/resets/12.1-more_mapping/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
my_numbers = [23,234,345,4356234,243,43,56,2]

# Your code here

print(new_list)
6 changes: 6 additions & 0 deletions .learn/resets/12.2-Map_function_inside_variable/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
names = ['Alice', 'Bob', 'Marry', 'Joe', 'Hilary', 'Stevia', 'Dylan']

def prepender(name):
return "My name is: " + name

# Your code here
9 changes: 9 additions & 0 deletions .learn/resets/12.3-Map_data_types/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mixed_list = ['1','5','45','34','343','34',6556,323]

def type_list(items):
# Your code here
return

new_list = list(map(type_list, mixed_list))

print(new_list)
23 changes: 23 additions & 0 deletions .learn/resets/12.4-Map_list_of_objects/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import datetime

people = [
{ "name": 'Joe', "birth_date": datetime.datetime(1986,10,24) },
{ "name": 'Bob', "birth_date": datetime.datetime(1975,5,24) },
{ "name": 'Erika', "birth_date": datetime.datetime(1989,6,12) },
{ "name": 'Dylan', "birth_date": datetime.datetime(1999,12,14) },
{ "name": 'Steve', "birth_date": datetime.datetime(2003,4,24) }
]

def calculate_age(date_of_birth):
today = datetime.date.today()
age = today.year - date_of_birth.year - ((today.month, today.day) < (date_of_birth.month, date_of_birth.day))
return age

def format_greeting(person):
# Your code here
return person["name"]


name_list = list(map(format_greeting, people))

print(name_list)
4 changes: 4 additions & 0 deletions .learn/resets/12.5-Yes_and_no/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
the_bools = [0,1,0,0,1,1,1,0,0,1,0,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,1]

# Your code here

10 changes: 10 additions & 0 deletions .learn/resets/12.6-Transformers/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
incoming_ajax_data = [
{ "name": 'Mario', "last_name": 'Montes' },
{ "name": 'Joe', "last_name": 'Biden' },
{ "name": 'Bill', "last_name": 'Clon' },
{ "name": 'Hilary', "last_name": 'Mccafee' },
{ "name": 'Bobby', "last_name": 'Mc birth' }
]

# Your code here

10 changes: 10 additions & 0 deletions .learn/resets/13-Filter_list/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
all_numbers = [23,12,35,5,3,2,3,54,3,21,534,23,42,1]


def filter_function(item):
# Update here
return item % 2 == 1

greater_than_ten = list(filter(filter_function, all_numbers))

print(greater_than_ten)
9 changes: 9 additions & 0 deletions .learn/resets/13.1-Filter_and_list/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
all_names = ["Romario", "Boby", "Roosevelt", "Emiliy", "Michael", "Greta", "Patricia", "Danzalee"]

# Your code here

print(resulting_names)




14 changes: 14 additions & 0 deletions .learn/resets/13.2-filter_done_tasks/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tasks = [
{ "label": 'Eat my lunch', "done": True },
{ "label": 'Make the bed', "done": False },
{ "label": 'Have some fun', "done": False },
{ "label": 'Finish the replits', "done": False },
{ "label": 'Replit the finishes', "done": True },
{ "label": 'Ask for a raise', "done": False },
{ "label": 'Read a book', "done": True },
{ "label": 'Make a trip', "done": False }
]


# Your code here

3 changes: 3 additions & 0 deletions .learn/resets/13.3-Filter_list_strings/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
names = ['Liam','Emma','Noah','Olivia','William','Ava','James','Isabella','Logan','Sophia','Benjamin','Mia','Mason','Charlotte','Elijah','Amelia','Oliver','Evelyn','Jacob','Abigail','Lucas','Harper','Michael','Emily','Alexander','Elizabeth','Ethan','Avery','Daniel','Sofia','Matthew','Ella','Aiden','Madison','Henry','Scarlett','Joseph','Victoria','Jackson','Aria','Samuel','Grace','Sebastian','Chloe','David','Camila','Carter','Penelope','Wyatt','Riley']

# Your code here
12 changes: 12 additions & 0 deletions .learn/resets/13.4-Making_HTML_with_filter_and_maP/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
all_colors = [
{"label": 'Red', "sexy": True},
{"label": 'Pink', "sexy": False},
{"label": 'Orange', "sexy": True},
{"label": 'Brown', "sexy": False},
{"label": 'Pink', "sexy": True},
{"label": 'Violet', "sexy": True},
{"label": 'Purple', "sexy": False},
]

# Your code here

5 changes: 5 additions & 0 deletions exercises/11-Nested_list/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
coordinates_list = [[33.747252, -112.633853], [-33.867886, -63.987], [41.303921, -81.901693], [-33.350534, -71.653268]]

# Your code here
latititud = []
longitude = []

for coor in coordinates_list:
print(coor[1])
3 changes: 1 addition & 2 deletions exercises/12-Map_a_list/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

def celsius_to_fahrenheit(celsius):
# The magic happens here

return (celsius * 9/5)+32

result = list(map(celsius_to_fahrenheit, celsius_values))

print(result)
4 changes: 4 additions & 0 deletions exercises/12.1-more_mapping/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
my_numbers = [23,234,345,4356234,243,43,56,2]

# Your code here
# new_list = []
def multiply_by_three(num):
return num*3

new_list = list(map(multiply_by_three, my_numbers))
print(new_list)
1 change: 1 addition & 0 deletions exercises/12.2-Map_function_inside_variable/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ def prepender(name):
return "My name is: " + name

# Your code here
print(list(map(prepender,names)))
2 changes: 1 addition & 1 deletion exercises/12.3-Map_data_types/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

def type_list(items):
# Your code here
return
return type(items)

new_list = list(map(type_list, mixed_list))

Expand Down
3 changes: 1 addition & 2 deletions exercises/12.4-Map_list_of_objects/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def calculate_age(date_of_birth):

def format_greeting(person):
# Your code here
return person["name"]

return f'Hello, my name is {person["name"]} and I am {calculate_age(person["birth_date"])} years old'

name_list = list(map(format_greeting, people))

Expand Down
6 changes: 6 additions & 0 deletions exercises/12.5-Yes_and_no/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
the_bools = [0,1,0,0,1,1,1,0,0,1,0,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,1]

# Your code here
def wiki_woko(number):
if number == 1:
return "wiki"
elif number == 0:
return "woko"

print(list(map(wiki_woko, the_bools)))
3 changes: 3 additions & 0 deletions exercises/12.6-Transformers/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
]

# Your code here
def data_transformer(users):
return list(map(lambda user: f'{user["name"]} {user["last_name"]}', users))

print(data_transformer(incoming_ajax_data))
2 changes: 1 addition & 1 deletion exercises/13-Filter_list/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def filter_function(item):
# Update here
return item % 2 == 1
return item > 10

greater_than_ten = list(filter(filter_function, all_numbers))

Expand Down
4 changes: 4 additions & 0 deletions exercises/13.1-Filter_and_list/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
all_names = ["Romario", "Boby", "Roosevelt", "Emiliy", "Michael", "Greta", "Patricia", "Danzalee"]

# Your code here
def starts_with_r(name):
if name[0]=="R":
return name

resulting_names = list(filter(starts_with_r,all_names))
print(resulting_names)


Expand Down
2 changes: 1 addition & 1 deletion exercises/13.2-filter_done_tasks/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@


# Your code here

print(list(filter(lambda task : task["done"], tasks)))
4 changes: 4 additions & 0 deletions exercises/13.3-Filter_list_strings/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
names = ['Liam','Emma','Noah','Olivia','William','Ava','James','Isabella','Logan','Sophia','Benjamin','Mia','Mason','Charlotte','Elijah','Amelia','Oliver','Evelyn','Jacob','Abigail','Lucas','Harper','Michael','Emily','Alexander','Elizabeth','Ethan','Avery','Daniel','Sofia','Matthew','Ella','Aiden','Madison','Henry','Scarlett','Joseph','Victoria','Jackson','Aria','Samuel','Grace','Sebastian','Chloe','David','Camila','Carter','Penelope','Wyatt','Riley']

# Your code here
def am_in_name(name):
if "am" in name or "Am" in name:
return name
print(list(filter(am_in_name,names)))
8 changes: 8 additions & 0 deletions exercises/13.4-Making_HTML_with_filter_and_maP/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@

# Your code here

def generate_li(color):
return f'<li>{color["label"]}</li>'

def filter_colors(item):
return item['sexy']


print(list(map(generate_li, list(filter(filter_colors, all_colors)))))
Loading