Проблема:
Дана строка, например, foobar, вы хотите получить список всех суффиксов этой строки, например, ["r", "ar", "bar", "obar", "oobar", "foobar"]
Решение
Используйте этот сниппет:
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