Zum Hauptinhalt springen
LIVE
CVSS 6.9CVE-2026-137684 | A security flaw has been discovered in eosphoros-ai DB-GPT up to 0.8.3. This affects the function editor_sql_run of the file packages/dbgpt-app/src/dbgpt_app/openapi/api_v1/editor/api_editor_v1.py of the component Editor SQL Run API. Performing a manipulation of the argument db_name results in authorization bypass. It is possible to initiate the attack remotely. The exploit has been released to the public and may be used for attacks. The pull request to fixCVSS 8.7CVE-2026-137992 | libexpat through 2.11.0 contains a denial of service vulnerability in defineAttribute() of lib/xmlparse.c that fails to detect duplicate non-ID #IMPLIED or #REQUIRED attribute declarations. Attackers can supply a crafted XML document with repeated ATTLIST declarations in an internal DTD subset to cause quadratic CPU consumption in storeAtts() during parsing.CVSS 8.5CVE-2026-137994 | Leo through 6.8.10 contains an insecure deserialization vulnerability that allows attackers to execute code by embedding pickled data in unknown XML attributes of .leo outlines. Attackers can place a pickle __reduce__ gadget in a or element attribute that resolveUa passes to pickle.loads, executing code with user privileges when the outline is opened.CVSS 7.0CVE-2026-137995 | FOG Project before 1.6.0.119 contains an information disclosure vulnerability that allows unauthenticated attackers to obtain host tokens from status/hostgetkey.php by supplying a host MAC address. Attackers can present the token to service/hostinfo.php to retrieve decrypted Active Directory join credentials and Windows product keys during deployment windows.CVSS 6.8CVE-2026-137996 | Zettlr before 4.11.0 fails to validate URI schemes in Markdown link targets, allowing attackers to launch arbitrary registered protocol handlers via Electron shell.openExternal without confirmation. Attackers can craft documents whose Ctrl/Cmd-clicked links use smb:// to leak NTLM credential hashes on Windows or invoke custom protocol handlers with attacker-controlled parameters.CVSS 8.5CVE-2026-137997 | HCIPy through 0.7.1 contains an insecure deserialization vulnerability that allows attackers to execute code by supplying crafted .pkl files to read_field, read_grid or read_mode_basis. Because hcipy/util/io.py selects pickle by file extension and calls pickle.load, a __reduce__ gadget in a pupil, apodizer, PSF or mode-basis file runs code with the user's privileges.CVSS 8.5CVE-2026-137998 | Detoxify 0.5.3 through 0.5.4 contains an insecure deserialization vulnerability in load_checkpoint that allows attackers to execute code by supplying a crafted checkpoint file. Attackers can embed a pickle __reduce__ gadget in a .ckpt file loaded via torch.load with weights_only=False to run code with the user's privileges.CVSS 8.5CVE-2026-137999 | JSONSchema2PoPo2 through 3.0.3 contains a code injection vulnerability that allows attackers to inject Python code by supplying JSON Schema default or format values that are written unescaped. Attackers can place a single quote in a string property default to break out of the literal in the generated __init__ signature, executing injected code when the generated module is imported.
Alle im Drawer
Intelligence View
⚡ tsecurity.de Intelligence

Python for Beginners — Part 5: Collections

Part 5 of a beginner-friendly series on learning Python from scratch. In Part 4, we learned how to make decisions and repeat code with loops. Now we're going…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Quelle & Fakten · 7 Min. Lesezeit
Quelle: dev.to
Rubrik: Programación segura

Part 5 of a beginner-friendly series on learning Python from scratch.



In Part 4, we learned how to make decisions and repeat code with loops. Now we're going to upgrade that power dramatically: instead of working with single values, we'll work with entire collections of data.



This is where Python becomes truly versatile. Collections let you store multiple values in a single variable, organize data logically, and iterate over it with the loops you just learned. Most real programs spend their time managing collections.






Lists — Ordered, Changeable Collections



A list is a container that holds multiple values in a specific order. You can add, remove, or change items after creating the list.






Creating and accessing lists






fruits = ["apple", "banana", "cherry"]
numbers = [1, 2, 3, 4, 5]
mixed = [1, "hello", 3.14, True]






Lists use square brackets and items are separated by commas. Items can be different types.



Access items by their index (position), just like strings:




fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # apple
print(fruits[1]) # banana
print(fruits[-1]) # cherry (last item)






Get the length with len():




print(len(fruits))  # 3









Slicing lists



Just like strings, lists can be sliced:




numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(numbers[0:3]) # [1, 2, 3]
print(numbers[5:]) # [6, 7, 8, 9, 10]
print(numbers[::2]) # [1, 3, 5, 7, 9] (every 2nd item)









Essential list methods



Lists come with many built-in methods. Here are the most important:




fruits = ["apple", "banana"]

# Add items
fruits.append("cherry") # Add to the end
fruits.insert(1, "mango") # Insert at specific position
fruits.extend(["date", "elderberry"]) # Add multiple items

# Remove items
fruits.remove("banana") # Remove by value
fruits.pop() # Remove last item and return it
fruits.pop(0) # Remove item at index 0
fruits.clear() # Remove all items

# Find and sort
numbers = [3, 1, 4, 1, 5, 9, 2, 6]
print(numbers.count(1)) # 2 (how many 1's)
print(numbers.index(4)) # 2 (position of 4)
numbers.sort() # Sort in place: [1, 1, 2, 3, 4, 5, 6, 9]
numbers.reverse() # Reverse in place

# Create a copy
numbers_copy = numbers.copy() # Independent copy






Important: sort() and reverse() change the list itself, not creating a new list. If you want to keep the original:




sorted_numbers = sorted(numbers)     # Returns a new sorted list









Modifying list items



Lists are mutable (changeable):




fruits = ["apple", "banana", "cherry"]
fruits[1] = "blueberry" # Change the second item
print(fruits) # ["apple", "blueberry", "cherry"]









Iterating over lists



Combine lists with the for loops from Part 4:




fruits = ["apple", "banana", "cherry"]

for fruit in fruits:
print(fruit)






Output:




apple
banana
cherry









List comprehension — concise list creation



List comprehension is a compact way to create a new list by transforming or filtering an existing one:




# Create a list of squares
numbers = [1, 2, 3, 4, 5]
squares = [x**2 for x in numbers]
print(squares) # [1, 4, 9, 16, 25]

# Filter: only even numbers
evens = [x for x in numbers if x % 2 == 0]
print(evens) # [2, 4]

# Transform and filter
result = [x * 2 for x in numbers if x > 2]
print(result) # [6, 8, 10]






Read it as: "Create a list of [transformation] for [each item] in [source list] if [condition]"



List comprehensions are faster and more Pythonic than building lists with loops. They're common in real code.






Tuples — Ordered, Unchangeable Collections



A tuple is like a list, but immutable (unchangeable). Once created, you can't add, remove, or modify items.






Creating tuples






colors = ("red", "green", "blue")
single_item = ("hello",) # Note the comma — without it, it's just a string
empty = ()






Use parentheses (round brackets). The comma is crucial for single-item tuples.






Accessing and iterating






colors = ("red", "green", "blue")
print(colors[0]) # red
print(colors[-1]) # blue
print(len(colors)) # 3

for color in colors:
print(color)









Unpacking tuples



Tuples shine when you want to assign multiple values at once:




x, y = (1, 2)
print(x) # 1
print(y) # 2

# The parentheses are optional
name, age, city = "Ramesh", 25, "Chennai"
print(name, age, city) # Ramesh 25 Chennai

# Swap variables easily
a, b = 1, 2
a, b = b, a # Now a=2, b=1









Why use tuples?





  • Speed: Slightly faster than lists (minor difference)


  • Safety: Immutable, can't accidentally modify


  • Keys in dictionaries: Tuples can be dict keys; lists can't


  • Function returns: Functions often return tuples of multiple values




def get_user():
return ("Ramesh", 25, "Chennai")

name, age, city = get_user()









Sets — Unique, Unordered Collections



A set is a collection of unique values with no specific order. Duplicates are automatically removed.






Creating sets






numbers = {1, 2, 3, 4, 5}
unique_letters = {"a", "b", "c", "a"} # 'a' appears once
print(unique_letters) # {'a', 'b', 'c'} (order may vary)

empty_set = set() # Note: {} creates an empty dict, not a set






Use curly braces. Sets have no indexing — you can't access the first item like you can with lists.






Common set operations






a = {1, 2, 3}
b = {3, 4, 5}

# Union — all items from both sets
print(a | b) # {1, 2, 3, 4, 5}
print(a.union(b)) # {1, 2, 3, 4, 5}

# Intersection — items in both sets
print(a & b) # {3}
print(a.intersection(b)) # {3}

# Difference — items in a but not b
print(a - b) # {1, 2}
print(a.difference(b)) # {1, 2}

# Check membership
print(3 in a) # True
print(4 in a) # False









Set methods






numbers = {1, 2, 3}
numbers.add(4) # Add one item
numbers.update([5, 6]) # Add multiple items
numbers.remove(2) # Remove item (error if not found)
numbers.discard(10) # Remove item (no error if not found)
numbers.clear() # Remove all items









Use cases for sets





  • Remove duplicates: unique = set([1, 2, 2, 3, 3, 3]) → {1, 2, 3}


  • Check membership: Sets are faster than lists for in checks


  • Mathematical operations: Union, intersection, difference






Dictionaries — Key-Value Pairs



A dictionary stores pairs of keys and values. You access values using their keys, not positions.






Creating dictionaries






person = {
"name": "Ramesh",
"age": 25,
"city": "Chennai"
}

scores = {"math": 95, "science": 87, "history": 92}
empty = {}






Use curly braces with key: value pairs. Keys are usually strings; values can be any type.






Accessing and modifying






person = {"name": "Ramesh", "age": 25}

print(person["name"]) # Ramesh
print(person["age"]) # 25

# Modify existing key
person["age"] = 26

# Add new key
person["city"] = "Chennai"

# Try to access non-existent key (safer way)
person.get("phone") # None (no error)
person.get("phone", "N/A") # N/A (default value)









Dictionary methods






person = {"name": "Ramesh", "age": 25, "city": "Chennai"}

# Get all keys, values, or pairs
print(person.keys()) # dict_keys(['name', 'age', 'city'])
print(person.values()) # dict_values(['Ramesh', 25, 'Chennai'])
print(person.items()) # dict_items([('name', 'Ramesh'), ('age', 25), ...])

# Iterate
for key in person:
print(f"{key}: {person[key]}")

# Iterate over pairs
for key, value in person.items():
print(f"{key}: {value}")

# Remove items
person.pop("age") # Remove and return value
person.popitem() # Remove last pair
person.clear() # Remove all

# Update from another dict
person.update({"phone": "555-1234", "age": 26})









Nested dictionaries



Dictionaries can contain other dictionaries (or lists, or tuples):




team = {
"player1": {"name": "Ramesh", "score": 95},
"player2": {"name": "Priya", "score": 87},
"player3": {"name": "Arun", "score": 92}
}

print(team["player1"]["name"]) # Ramesh
print(team["player2"]["score"]) # 87









Choosing the Right Collection











































Collection Ordered Changeable Duplicates Use Case
List ✓ ✓ ✓ Store sequence of items
Tuple ✓ ✗ ✓ Immutable sequences, dict keys
Set ✗ ✓ ✗ Unique values, membership checks
Dict ✓ (Python 3.7+) ✓ ✓ (values) Store labeled data, key-value lookup





Practical Examples






Example 1: Managing a to-do list






todos = []

# Add tasks
todos.append("Buy groceries")
todos.append("Finish project")
todos.append("Call mom")

# Mark as done (remove)
todos.remove("Buy groceries")

# Show remaining
for i, task in enumerate(todos):
print(f"{i+1}. {task}")






Output:




1. Finish project
2. Call mom









Example 2: Count word frequency






text = "the quick brown fox jumps over the lazy dog the fox"
words = text.split()
word_count = {}

for word in words:
if word in word_count:
word_count[word] += 1
else:
word_count[word] = 1

print(word_count)
# {'the': 3, 'quick': 1, 'brown': 1, 'fox': 2, ...}






Or more concisely:




from collections import Counter
word_count = Counter(words)
print(word_count)









Example 3: Find common interests






alice_interests = {"python", "music", "hiking", "gaming"}
bob_interests = {"python", "gaming", "cooking", "music"}

# What do they both enjoy?
common = alice_interests & bob_interests
print(common) # {'python', 'gaming', 'music'}

# What does Alice enjoy that Bob doesn't?
alice_unique = alice_interests - bob_interests
print(alice_unique) # {'hiking'}









Why This Matters



Collections are fundamental to every real program. You'll spend most of your programming time manipulating lists, dictionaries, and sets. Once you internalize which tool is right for each job, you'll write cleaner, faster code.



The most common beginner mistakes:




  • Confusing list and tuple syntax ([] vs ())

  • Trying to add items to a tuple (they're immutable!)

  • Using {} for an empty set and getting a dict instead

  • Trying to use lists as dictionary keys (they're unhashable)

  • Forgetting that dictionaries store by key, not position






This is Part 5 of an 8-part beginner Python series. Catch up on Part 1: Getting Started & Syntax, Part 2: Variables, Data Types & Numbers, Part 3: Strings & Booleans, and Part 4: Operators & Control Flow.

Information ergänzen Fachhinweis, Update, Korrektur oder Quelle zur Meldung beitragen
Gäste-Hinweise werden kurz redaktionell geprüft und danach hier angezeigt.

Community-Hinweise zur Meldung

0 freigegeben
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!
Informations-Bewertung:

💬 Debate de la comunidad y comentarios

🌐 Unirse al chat principal

Inicia el debate en el stream de difusión del Social Chat o envía arriba una contribución experta mediante el formulario de ampliación.

Valoración de la comunidad & prueba social
⭐ Valoración de los lectores
–
Ø / 5.0
Aún no hay valoraciones de lectores
¿Le ha resultado útil este artículo?
0
Dejar una valoración ahora
Valoración detallada (opcional)
Contenido & calidad
Fuente & credibilidad
Actualidad
Briefing de seguridad Gratis · baja en 1 clic

Intelligence Digest — gratis

Cada día las noticias de seguridad más importantes · baja en cualquier momento

Clústeres de historias relacionados & fuentes (IA vectorial)

2 Cluster
2 fuentes
OpenAI counter-sues Apple over trade secret theft
AppleInsider News hace 1 h
1 fuente más
Artículos similares
🔍 Verwandte News

Auch interessante Nachrichten Python for Beginners — Part 5: Collections

Thematisch verwandte Begriffe: Python, Beginners, Part, Collections · 6 Treffer

Laden...

Cargando artículos ...

Laden...

Cargando vídeos ...

Laden...

Cargando artículos ...

Laden...

Cargando vídeos ...

Laden...

Cargando artículos ...

Laden...

Cargando vídeos ...

Laden...

Cargando artículos ...

Laden...

Cargando vídeos ...

💬 Cargando comentarios…
Desliza para actualizar
Widgets & Topics
Loading widgets…
Nächster Beitrag