Meine erste eigene rekursive Funktion Ich habe eine kleine Funktion geschrieben, die die String-Methode partition nicht nur einmal aufruft, sondern so oft wie möglich. Weil ich genug Langeweile hatte, hab ich sie einmal als "normale Funktion" geschrieben und einmal als Methode einer Klasse, die von str erbt.
Hier der Code: http://paste.pocoo.org/show/108665/
partition_all
Und hier eine iterative Umsetzung:
Code: Alles auswählen
def partition_all(string, separator):
result = list()
while True:
head, separator, string = string.partition(separator)
if not separator:
break
result.append((head, separator, string))
return result