Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
•
Sichere ProgrammierungGoogles Gemini 4 Argon legt Fokus auf Cybersicherheit(01.10.2026 um 00:25 Uhr)
••
Sichere ProgrammierungOracle Manipulation Risk Report: Uniswap V3(01.10.2026 um 00:36 Uhr)
••••
Sichere ProgrammierungNever Trust, Always Verify: Zero-Trust Governance for MCP Memory(01.10.2026 um 00:48 Uhr)
••
Sichere ProgrammierungA wine cellar that remembers what you used to believe(01.10.2026 um 00:49 Uhr)
••
Sichere ProgrammierungGoogles Gemini 4 Argon legt Fokus auf Cybersicherheit(01.10.2026 um 00:25 Uhr)
••
Sichere ProgrammierungOracle Manipulation Risk Report: Uniswap V3(01.10.2026 um 00:36 Uhr)
••••
Sichere ProgrammierungNever Trust, Always Verify: Zero-Trust Governance for MCP Memory(01.10.2026 um 00:48 Uhr)
••
Sichere ProgrammierungA wine cellar that remembers what you used to believe(01.10.2026 um 00:49 Uhr)
•
Intelligence View
⚡ tsecurity.de Intelligence

Turning Tuples Mutable — Beyond list()

We all know that Python tuples are immutable—once created, you can't change their values directly. But what if you need to change their content? Most tutorials …

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!

We all know that Python tuples are immutable—once created, you can't change their values directly. But what if you need to change their content?



Most tutorials will tell you:




t = (1, 2, 3)
mutable_version = list(t)






Sure, this works. But let's explore other techy and creative ways to work with immutable data by transforming or decomposing tuples—without always falling back to a boring list().









🔍 Tuple to Dict via Enumeration



Sometimes, you need both index and value. Dictionaries are mutable and can be a neat transformation:




t = ("apple", "banana", "cherry")
d = dict(enumerate(t))
d[1] = "blueberry"
print(tuple(d.values())) # ('apple', 'blueberry', 'cherry')






Useful if you're working with positional elements and need to mutate by index.









🧹 Tuple Unpacking and Reconstruction



Another way is to decompose the tuple manually:




a, b, c = (10, 20, 30)
b = 200
t_new = (a, b, c)
print(t_new) # (10, 200, 30)






Simple but powerful — and keeps the tuple form intact. You can even use *args if you don’t know the length in advance.









🔄 Using collections.namedtuple (Bonus Tip!)



Want tuples with names and some flexibility?




from collections import namedtuple

Point = namedtuple('Point', ['x', 'y'])
p = Point(1, 2)
p = p._replace(x=10)
print(p) # Point(x=10, y=2)






You’re still using an immutable structure, but _replace lets you mutate-like-update with elegance.









🧠 TL;DR



Yes, list() is the go-to way, but you can also:




  • Convert to dict if indexes matter.

  • Unpack and rebuild for control.

  • Use namedtuple and _replace() for readable, structured code.



Next time someone says "just convert it to a list", hit them with these smarter tools. 😉

2. Cyber Threat Intelligence & Forensik

CTI Threat Relationship Graph2 Knoten / 1 Relationen
CVE / Incident Software MITRE ATT&CK CWE Weakness IoC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Turning Tuples Mutable — Beyond list()

Thematisch verwandte Begriffe: Turning, Tuples, Mutable, Beyond · 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 ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag