+ 1
Can I concatenate results of all 'for' iterations in one string or list?
I need the results of program below to be printed not "one result - one string" but "all results - one string" with spaces It should look like: 6 5 12 13 2 22 ...etc def string_res(): for i in range(len(text)): result=alph.find(text[i]) str_res="" if result>=0: str_res=str_res+str(result) else: str_res=str_res+text[i] print(str_res)
4 Respuestas
+ 4
alph = "abcdefghijklmnopqrstuvwxyz"
def string_res(text):
str_res = ""
for i in range(len(text)):
result = alph.find(text[i])
if result >= 0:
str_res = str_res+str(result)+" "
else:
str_res = str_res+text[i]
return str_res
print(string_res("g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."))
+ 2
You are great, really.
I was totally stumped
0
O, right😵
0
Alph is English alphabet
Text is the number of letters:
g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.