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

Ejercicio Javier Rodriguez #26

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

xrodrimo
Copy link

No description provided.

@bripollc
Copy link

Hola Xavi,

Felicidades! Buen lab!!! Te dejo algunas cosillas, más que nada despistes:)

  • Use a list comprehension to create and print a list of even numbers starting with 2 and ending with 200.
lista_even = [i+1 for i in range(1,201) if i % 2 !=0]
print(lista_even)

Como has especificado un rango de (1, 201) y usado i+1 para generar la lista, se agregará 1 a cada número hasta el 201. Tu código funciona ya que como tienes la condición para buscar los pares i % 2 !=0, se excluye el 201. En otro caso, estarías incluyendo un número extra en la lista, así que se debería ajustar el rango a (1, 200).

  • Add a condition to the list comprehension above so that only values greater than or equal to 0.5 are printed.

Solo un pequeño apunte. Te pide que sea igual o mayor a 0.5 por lo que se debería especificar if n >= 0.5.
También, si pones el código de tu comprehensión list en otra celda, se imprimirá el resultado. Como tienes arriba otro código en el que hay un pequeño error cuando declaras if element > 0.5 porque no has definido element, te sale un SyntaxError de toda la celda, pero tu comprehension list está bien:)

  • Use a list comprehension to create and print a list containing all elements of the 5 x 2 x 3 array below.
list_b = [lvl3 for lvl1 in b for lvl2 in lvl1 for lvl3 in lvl2]
print(list_b)

Ya casi lo tenías!

  • Add a condition to the list comprehension above so that the last value in each subarray is printed, but only if it is less than or equal to 0.5.
list_subarray = [n[-1] for i in b for n in i if n[-1] <= 0.5]
print(list_subarray)
  • Use a list comprehension to select and print the names of all CSV files in the /data directory. Mind slashes.
directory = ("../data")
file_lst = [i for i in os.listdir(directory) if i.endswith("csv")]
print(file_lst)

Te dejo la solución del último ejercicio:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants