Alle Suffixe eines Strings in Python abrufen (Suffix-Liste)
English
Deutsch
Problem:
Gegeben ein String, z.B. foobar, möchtest du die Liste aller Suffixe dieses Strings abrufen, z.B. ["r", "ar", "bar", "obar", "oobar", "foobar"]
Lösung
Verwende dieses Snippet:
all_suffixes.py
def all_suffixes(s):
return [s[-i:] for i in range(1, len(s) + 1)]
s = "foobar"
print(all_suffixes(s)) # ['r', 'ar', 'bar', 'obar', 'oobar', 'foobar']Check out similar posts by category:
Algorithms, Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow