DEV Community

Cristian Fernando
Cristian Fernando

Posted on • Edited on

Ibuprofeno.py💊| #20: Explica este código Python

Explica este código Python

Dificultad: Básico

list = [1,2,2,3,4,5,5,6]
set = set(list)
print(set)
Enter fullscreen mode Exit fullscreen mode
  • A. {1, 2, 3, 4, 5, 6}
  • B. {2, 2, 5, 5}
  • C. {1, 3, 4, 6}
  • D. {2, 5}

Respuesta en el primer comentario.

Top comments (1)

Collapse
 
duxtech profile image
Cristian Fernando

Respuesta:

  • A. {1, 2, 3, 4, 5, 6}

set es una estructura de datos similar a las listas pero con algunas diferencias: los items en un set no están indexados por posición y los set no admiten elementos repetidos.

Esto último es super importante para comprender este reto, en el mismo usamos la función set() para convertir una lista a un set, como este no puede contener elementos repetidos, en dicha conversión se perderán algunos items: un 2 y un 5.

El resultado final será un nuevo set sin dichos elementos repetidos.

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay