🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)
🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)

🔧 Programmierung 🕛 kürzlich 3 Min Lesezeit
0

Python Dictionaries and Sets: Organize Named Data and Remove Duplicates

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

When we start learning Python, lists are often one of the first data structures we use:




CODE
student = ["Laura", 24, "Medellín"]






This works, but what does each position represent?



We need to remember that:




  • Position 0 contains the name.

  • Position 1 contains the age.

  • Position 2 contains the city.



A dictionary provides a clearer alternative because every value is identified by a descriptive key.






Creating a dictionary



A dictionary stores information as key-value pairs:




CODE
student = {
"name": "Laura",
"age": 24,
"city": "Medellín"
}






Instead of asking for the value at position 0, we can ask directly for the value associated with "name":




CODE
print(student["name"])






Output:




CODE
Laura






A useful way to remember the difference is:




A list position tells you where a value is. A dictionary key tells you what the value means.







Updating and adding information



Python dictionaries are mutable, so their content can change after creation.



To update an existing value:




CODE
product = {
"name": "Keyboard",
"price": 120000
}

product["price"] = 110000






To add a new key-value pair, use the same syntax with a key that does not exist yet:




CODE
product["available"] = True






The resulting dictionary is:




CODE
{
"name": "Keyboard",
"price": 110000,
"available": True
}









Safely reading values with get()



Using square brackets requires the key to exist:




CODE
print(student["email"])






If "email" is missing, Python raises a KeyError.



The get() method provides a safer alternative:




CODE
print(student.get("email"))






It returns None when the key is missing.



You can also define a default value:




CODE
print(student.get("email", "Not registered"))






Output:




CODE
Not registered






To check whether a key exists, use the in operator:




CODE
if "city" in student:
print(student["city"])









Keys, values, and pairs



Python provides three useful dictionary methods:




CODE
course = {
"name": "Python Basics",
"duration": "4 weeks",
"format": "Online"
}

print(course.keys())
print(course.values())
print(course.items())






They provide different views of the same information:





  • keys() returns the keys.


  • values() returns the stored values.


  • items() returns complete key-value pairs.






Looping through a dictionary



The items() method is especially useful when working with a for loop:




CODE
capitals = {
"Colombia": "Bogotá",
"Peru": "Lima",
"Argentina": "Buenos Aires"
}

for country, capital in capitals.items():
print(f"{country}: {capital}")






Output:




CODE
Colombia: Bogotá
Peru: Lima
Argentina: Buenos Aires






During every iteration, Python assigns the current key to country and its associated value to capital.






What is a set?



A set is a collection that stores unique values.



Consider this list:




CODE
languages = ["Python", "Rust", "Python", "JavaScript", "Rust"]






We can remove repeated values by converting it into a set:




CODE
unique_languages = set(languages)

print(unique_languages)






The set keeps only one occurrence of each language.



Sets are useful when you need to:




  • Remove duplicate values.

  • Check whether a value is present.

  • Compare groups of elements.

  • Work with unique categories or identifiers.



Unlike lists, sets do not support indexes or slicing.






An important detail



Empty braces create an empty dictionary:




CODE
empty_dictionary = {}






To create an empty set, use set():




CODE
empty_set = set()






This is a common source of confusion for Python beginners.






Which structure should you choose?



Use a list when position and order are important.



Use a dictionary when every value should have a descriptive name.



Use a set when you need unique values and repetitions do not matter.



Understanding this distinction makes programs easier to read, maintain, and extend.



The original Spanish guide includes a step-by-step explanation with additional examples:



https://tucodigocotidiano.yarumaltech.com/leer_guias/diccionarios-y-conjuntos-datos-con-nombre-y-sin-duplicados/



What was more confusing when you first learned Python: dictionaries or sets?

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
GPT-6 Astra Release Today? OpenAI’s Next Major AI Model Is Almost Here
1 Quelle
Apple accuses OpenAI of destroying evidence as trade-secrets fight intensifies
1 Quelle
Major AI platforms go down in unprecedented simultaneous outage
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Python Dictionaries and Sets: Organize Named Data and Remove Duplicates

Thematisch verwandte Begriffe: Python, Dictionaries, Sets, Organize · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...