mam ciąg w Pythonie, powiedzmy The quick @red fox jumps over the @lame brown dog.
Python zastąpić wzór ciąg z wyjściem funkcji
próbuję zastąpić każde z tych słów, które rozpoczynają się @
z wyjściem funkcję, która pobiera jako słowo argument.
def my_replace(match):
return match + str(match.index('e'))
#Psuedo-code
string = "The quick @red fox jumps over the @lame brown dog."
string.replace('@%match', my_replace(match))
# Result
"The quick @red2 fox jumps over the @lame4 brown dog."
Czy istnieje sprytny sposób na zrobienie tego?
to, co masz, jest dobre. robisz to w jednym komunikacie. – tuxuday