Wenn du ein Python Script zum Erzeugen von Zeichenkombinationen suchst, bist du hier genau richtig. In diesem Beitrag zeigen wir dir, wie du mit einem einfachen Python-Skript alle möglichen Buchstabenkombinationen generieren kannst – mit einem festen Buchstaben am Ende – und die Ergebnisse als CSV- und JSON-Datei exportierst.
🔧 Was macht das Python-Script?
Das Skript erstellt mit Hilfe der Standardbibliothek itertools alle dreistelligen Kombinationen von Großbuchstaben (A–Z) und hängt automatisch den Buchstaben „U“ an jede Kombination an. Am Ende stehen also 4-stellige Codes, die alle auf „U“ enden – beispielsweise AAAU, BBBU, ZZZU.
Das Python Script speichert die generierten Kombinationen anschließend in zwei gängigen Formaten:
CSV-Datei – ideal für Excel, Datenbanken oder Tabellen-Importe
JSON-Datei – perfekt für APIs, Webentwicklung oder strukturierte Datenverarbeitung
💻 Der vollständige Python Code
1import csv
2import json
3import itertools
4
5# Script to create a list of possible combinations of four letters, where the last letter is always a U.
6
7letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
8
9# create all possible combinations of four letters, where the last one is a 'U'
10combinations = list(itertools.product(letters, repeat=3))
11codes = [''.join(combination) + 'U' for combination in combinations]
12
13# output as CSV
14with open('codes.csv', 'w', newline='') as csvfile:
15 writer = csv.writer(csvfile)
16 writer.writerow(['Code'])
17 writer.writerows([[code] for code in codes])
18
19# output as JSON
20with open('codes.json', 'w') as jsonfile:
21 json.dump({'Codes': codes}, jsonfile)
22
23print("CSV and JSON files have been successfully created.")
24
25# run python3 codes.py
Published: 4/21/2025