+ 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)

13th Nov 2019, 3:31 PM
Julia Myslitskaya
Julia Myslitskaya - avatar
5 Answers
+ 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."))
13th Nov 2019, 4:08 PM
Diego
Diego - avatar
+ 2
You are great, really. I was totally stumped
13th Nov 2019, 4:15 PM
Julia Myslitskaya
Julia Myslitskaya - avatar
0
O, rightđŸ˜”
13th Nov 2019, 3:41 PM
Julia Myslitskaya
Julia Myslitskaya - avatar
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.
13th Nov 2019, 3:42 PM
Julia Myslitskaya
Julia Myslitskaya - avatar