No tienes acceso a esta clase

¡Continúa aprendiendo! Únete y comienza a potenciar tu carrera

Última oportunidad para asegurar tu aprendizaje por 1 año a precio especial

Antes: $249

Currency
$189/año

Paga en 4 cuotas sin intereses

Paga en 4 cuotas sin intereses
Suscríbete

Termina en:

0D
8H
9M
1S

Playgrounds: Agrega solo los números positivos de una lista

33/37

Aportes 377

Preguntas 9

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad?

o inicia sesión.

Primer comentario y aporte en todo lo que llevo de Platzi, buena estrategia esta de los playground.

si alguien se pregunta como hacerlo con un whiel

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

Escribe tu solución 👇

i = len(my_list)
counter = 0
while counter < i:
if my_list[counter] > 0:
new_list.append(my_list[counter])
counter += 1
print(new_list)

SIUUUUUUU

for element in my_list:
  if element > 0:
    new_list.append (element)

print(new_list)

Aqui mi solucion:

lista = [1,2,3,4,-8,-9,15,44,-896]
new_lista= []
for e in lista:
  if e < 0:
    continue
  else:
    new_lista.append(e)

print(new_lista)

# [1, 2, 3, 4, 15, 44]

Recuerda colocar el print() en todo el comienzo de la línea.

Hola, les comparto mi versión de una solución del playground, luego de varios intentos fallidos 😅

new_list = [num for num in my_list if num >= 0]

asi que chiste , si todos ponen sus respuestas

Genial los Playgrounds!

Solución:

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

# Escribe tu solución 👇
for number in my_list:
  if not number < 0:
    new_list.append(number)

print(new_list)

for i in my_list:
if i > 0:
new_list.append(i)
print(new_list)

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

# Escribe tu solución 👇

for i in my_list:
    if i >= 0:
        new_list.append(i)
print(new_list)

Mi manera de resolverlo, no se si sea la más correcta pero funciona

for i in  range(len(my_list)):
    break
my_list.sort()
new_list = print(my_list[4:])

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

for number in my_list:
if number >= 0:
new_list.append(number)

print(new_list)

Que buen ejercicio

Mi solución!!

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

Escribe tu solución 👇

for element in my_list:
if element >0:
new_list.append(element)

print(new_list)

Este es mi código para depurar la lista original y que la nueva
lista sólo sea de números positivos:

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

# Escribe tu solución 👇

for element in my_list:
  if element > 0:
    new_list.append(element)
    
print(new_list)

La imagen de la corrida se muestra a continuación:

![](

Una solución posible para el ejercicio:

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

# Escribe tu solución 👇
for number in my_list:
  if number>0:
    new_list.append(number)

print(new_list)

for new_list in range (1,5):
new_list = [1, 2, 3, 4]
print(new_list)

HAsta que por fin lo logre errores que cometo por no ser detallista.

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

# Escribe tu solución 👇
for i in my_list:
  if i > 0:
    new_list.append(i)

print(new_list)
# declaración e inicialización de variables
my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

# Escribe tu solución 👇
#ciclo
for number in my_list:
  if number > 0:
    new_list.append(number)
# output
print(new_list)

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

Escribe tu solución 👇

for i in my_list:
if i > 0:
new_list.append(i)
print(new_list)

Solucionado

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []
for i in my_list:
if i > 0:
new_list.append(i)
print(new_list)

Mi solucion

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

Escribe tu solución 👇

for element in my_list:
if element > 0:
new_list.append(element)
print(new_list)

for number in my_list:
if number > 0:
new_list.append(number)
print (new_list)

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

Escribe tu solución 👇

for i in my_list:
if i > 0:
new_list.append(i)

print(new_list)

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

# Escribe tu solución 👇

for positivos in my_list:
  if positivos >= 0:
    new_list.append(positivos)
print(new_list)

![](https://static.platzi.com/media/user_upload/image-72fb6ebf-fb42-4f65-b94b-a9e49ed11a6f.jpg) Usando al viejo i, recordando a C
```python my_list = [1, -1, 2, -2, 3, -3, 4, -4] new_list = [] # Escribe tu solución 👇 for element in my_list: if element > 0: new_list.append(element) print(new_list) ```my\_list = \[1, -1, 2, -2, 3, -3, 4, -4]new\_list = \[] \# Escribe tu solución 👇for element in my\_list: if element > 0: new\_list.append(element) print(new\_list)
```js my_list = [1, -1, 2, -2, 3, -3, 4, -4] new_list = [] # Escribe tu solución 👇 for element in my_list: if element > 0: new_list.append(element) print(new_list) ```my\_list = \[1, -1, 2, -2, 3, -3, 4, -4]new\_list = \[] \# Escribe tu solución 👇for element in my\_list: if element > 0: new\_list.append(element) print(new\_list)
my\_list = \[1, -1, 2, -2, 3, -3, 4, -4]new\_list = \[] \# Escribe tu solución 👇for n in my\_list:  if n>0:    new\_list.append(n) print(new\_list)
my\_list = \[1, -1, 2, -2, 3, -3, 4, -4]new\_list = \[i for i in my\_list if i >= 0] \# Escribe tu solución 👇 print(new\_list)
`my_list = [1, -1, 2, -2, 3, -3, 4, -4]new_list = []` `# Escribe tu solución 👇for n in my_list:  if not n < 0:    new_list.append(n)print(new_list)`
```js my_list = [1, -1, 2, -2, 3, -3, 4, -4] new_list = [] # Escribe tu solución 👇 for i in my_list: if i >0: new_list.append(i) print(new_list) ```my\_list = \[1, -1, 2, -2, 3, -3, 4, -4]new\_list = \[] \# Escribe tu solución 👇for i in my\_list:  if i >0:    new\_list.append(i)    print(new\_list)
```js for number in my_list: if number >=0: new_list.append(number) ```for number in my\_list:  if number >=0:    new\_list.append(number)
![](https://static.platzi.com/media/user_upload/image-417b295d-a89b-4074-a93c-8a1da693c077.jpg)![](https://static.platzi.com/media/user_upload/image-6ed2aba2-f661-4206-a3fe-d224b1301b81.jpg)

Esta seria una forma optimizada

new_list = [num for num in my_list if num > 0]
print(new_list)
my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

# Escribe tu solución 👇
for i in my_list:
  if(i > 0):
    new_list.append(i)

print(new_list)

Acá dejo mi humilde aporte:

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

for num in my_list:
  if num < 0:
    continue
  new_list.append(num);
  
print(new_list)
Estoy volando! ![](https://static.platzi.com/media/user_upload/image-dc7cb57b-ad10-4789-a765-518abc5b7932.jpg)
estoy confundido de verdad, en el examen sale bien pero en la practica es otra cosa :'C ![](https://static.platzi.com/media/user_upload/image-ab7b10d3-aed7-4ecb-820c-66e7d80975f5.jpg)
```js my_list = [1, -1, 2, -2, 3, -3, 4, -4] # Escribe tu solución 👇 new_list = [x for x in my_list if x >= 0] print(new_list) ```
```python my_list = [1, -1, 2, -2, 3, -3, 4, -4] new_list = [] # Escribe tu solución 👇 for number in my_list: if number > 0: new_list.append(number) print(new_list) ```

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

Escribe tu solución 👇

for number in my_list:
if not number < 0:
new_list.append(number)

print(new_list)

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []
for number in my_list:
  if not number < 0:
    new_list.append(number)
# Escribe tu solución 👇


print(new_list)

for number in my_list:
if not number < 0:
new_list.append(number)
print(new_list)

me dio a la primera my\_list = \[1, -1, 2, -2, 3, -3, 4, -4]new\_list = \[] \# Escribe tu solución 👇 for number in my\_list:  if not number <0:    new\_list.append(number)print(new\_list)
for elemento in my_list:
  if elemento > 0:
    new_list.append(elemento)
    

print(new_list)

Este ejercicio estuvo interesante para medir mis conocimientos con la programacion. Es algo que no olvidare.

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []
for number in my_list:
    if number > 0:
        new_list.append(number)
print(new_list)
![](https://static.platzi.com/media/user_upload/resuelto-9d806f2d-77d2-4516-a8ec-9dc5459eb979.jpg)
```python my_list = [1, -1, 2, -2, 3, -3, 4, -4] new_list = [] for item in my_list: if item > 0: new_list.append(item) print(new_list) ```
my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

# Escribe tu solución 👇

for item in my_list:
    if item > 0:
        new_list.append(item)

print(new_list)
![](https://static.platzi.com/media/user_upload/image-d6343c17-bd59-4a14-a742-d105a463dd12.jpg) Mi solución
my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

# Escribe tu solución 👇
for number in my_list:
  if  not number < 0:
    new_list.append(number)
print(new_list)
![](https://static.platzi.com/media/user_upload/image-2e885ed1-27dc-44f7-b008-cedba6968d92.jpg)![](https://static.platzi.com/media/user_upload/image-b7b24585-8ffd-4752-a822-bbe4b60ac6f7.jpg) Listo

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

Escribe tu solución 👇

for element in my_list:
if element >0:
new_list.append(element)

print(new_list)

Compas les comparto mi solucion: `for item in my_list:  if item > 0:    new_list.append(item)` `print(new_list)`
![](https://static.platzi.com/media/user_upload/image-012d5bb2-adb3-4314-b52c-1e9f589c07b9.jpg)
Holas: No entiendo por que si mi código se ejecuta y esta bien, cuando corre la prueba sale error: ![]()![](https://static.platzi.com/media/user_upload/image-0dd23e7a-7520-4e00-81e0-d4a86d560804.jpg)![]()![](https://static.platzi.com/media/user_upload/image-984241c4-4717-4d01-8271-3037a1a07427.jpg) ![](https://static.platzi.com/media/user_upload/image-53eb9de2-4fdf-4217-b26f-92eec13f6c10.jpg)
new\_list = \[]for number in my\_list: if number > 0: new\_list.append(number)print(new\_list)
```js new_list = [] for number in my_list: if number > 0: new_list.append(number) print(new_list) ```new\_list = \[]for number in my\_list: if number > 0: new\_list.append(number)print(new\_list)
Mi aporte... ```python new_list = [] for number in my_list: if number > 0: new_list.append(number) print(new_list) ```new\_list = \[]for number in my\_list: if number > 0: new\_list.append(number)print(new\_list)print(new\_list)

solucion del reto

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

# Escribe tu solución 👇
for i in my_list:
  if i > 0:
    new_list.append(i)


print(new_list)
`the first code...` `my_list = [1, -1, 2, -2, 3, -3, 4, -4]` `positive_numbers = []` `for number in my_list:` ` if number < 0:` ` continue` ` positive_numbers.append(number)` `print(positive_numbers)` ` `
![](https://static.platzi.com/media/user_upload/numeros-153bb9a9-9cb7-487b-aaf8-7cbc9788b1f6.jpg)
![](https://static.platzi.com/media/user_upload/image-e9f2c5eb-4c60-44ed-bf38-b86e8e1e9b76.jpg)
![](https://static.platzi.com/media/user_upload/Captura%20de%20pantalla%202023-09-26%20a%20la%28s%29%203.43.37%20p.m.-873fe285-98c9-4310-8d51-1965dee7c411.jpg)
Mi solución ^^ ```js my_list = [1, -1, 2, -2, 3, -3, 4, -4] new_list = [] # Escribe tu solución 👇 for elemento in my_list: if elemento < 0: continue new_list.append(elemento) print(new_list) ```my\_list = \[1, -1, 2, -2, 3, -3, 4, -4]new\_list = \[] \# Escribe tu solución 👇for elemento in my\_list:  if elemento < 0:    continue  new\_list.append(elemento) print(new\_list)
![](file:///C:/Users/Jarvis%20xd/Pictures/Screenpresso/2023-09-25_10h50_04.png)![]()![](<C:\Users\Jarvis xd\Pictures\Screenpresso\2023-09-25_10h50_04.png>)
```python my_list = [1, -1, 2, -2, 3, -3, 4, -4] new_list = [] for item in my_list: if item < 0: continue new_list.append(item) print(new_list) ```

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

Escribe tu solución 👇

for positivos in my_list:
if positivos > 0:
new_list.append(positivos)

print(new_list)

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

# Escribe tu solución 👇


for i in my_list:
  if not i < 0:
    new_list.append(i)

print(new_list)

for i in my_list:
if i > 0:
new_list.append(i)
print(new_list)

for i in my_list:
if i > 0:
#print(i)
new_list.append(i)

print(new_list)


my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

for i in my_list:
  if i > 0: new_list.append(i)

print(new_list)

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

Escribe tu solución 👇

for element in my_list:
if(element>0):
new_list.append(element)

print(new_list)

Lo solucioné de la siguiente forma:

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

Escribe tu solución 👇

for num in my_list:
if num > 0:
new_list.append(num)

print(new_list)

Otra forma de hacerlo usando el continue

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

for item in my_list:
  if item < 0:
    continue
  new_list.append(item)

print(new_list)

Mi solución:

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

# Escribe tu solución 👇
for i in my_list:
  if i>0:
    new_list.append(i)

print(new_list)

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

Escribe tu solución 👇

for element in my_list:
if element > 0:
new_list.append(element)
print(new_list)

Mi respuesta

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

# Escribe tu solución 👇
for lista in my_list:
  if lista < 0:
    continue
  else:
    new_list.append(lista)

print(new_list)

yo encontré esta solución, espero sus comentarios


my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []
print(“entrada =>”,my_list)
my_list.sort()
del my_list[:-4]
new_list= my_list
print(new_list)


my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

Escribe tu solución 👇

for i in my_list:
if(i>0):
new_list.append(i)

print(new_list)

my_list = [1, -1, 2, -2, 3, -3, 4, -4]
new_list = []

# Escribe tu solución 👇
for number in my_list :
  if number > 0:
    new_list.append(number)

print(new_list)
undefined