[SOLVED]How to substitute int with their ascii value in a string? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

[SOLVED]How to substitute int with their ascii value in a string?

Suppose a list: ["hello116her101", "wh97116isu112"] I want to substitute int with their ascii value between a-z (97-123). Then output list will be: ["hellothere", "whatisup"] The main problem i am facing is with integers in groups like "97116" which should become "at" (97=a & 116=t).

1st Apr 2021, 2:27 PM
Carlos
Carlos - avatar
9 Answers
+ 2
Carlos I wrote this last night, but then I got tired and went to sleep when you replied. I have tried it and it looks okay so far, but I haven't tested it thoroughly, so if there's a problem, please reply mentioning the words to test, so I can try to fix it. https://code.sololearn.com/c1BFTHYcAy1O/?ref=app
2nd Apr 2021, 1:15 AM
Ipang
+ 1
The challenge here I guess , is to correctly predict how many digits is to be read to be converted to a character.
1st Apr 2021, 3:16 PM
Ipang
+ 1
Ipang yeah i believe the guess should be between 2 to 3 chars. Then can it be: If len(integers chars checked)==2 Then substitute If len(integers chars checked)==3 Then substitute ??? As if an integer less than 97 pops up then the substitution should skip??
1st Apr 2021, 3:26 PM
Carlos
Carlos - avatar
+ 1
Ipang I am actually really confused about my code😵 https://code.sololearn.com/c2l7xCukzfzP/?ref=app And this undebugable error makes me worse.
1st Apr 2021, 4:27 PM
Carlos
Carlos - avatar
+ 1
Ipang Nicee!! That's what I wanted . It is the best i could have thought of. I have tried many possible conditions in your code and it passes all. Thanks very much!!😃
2nd Apr 2021, 4:27 AM
Carlos
Carlos - avatar
+ 1
Ipang I have also tried to solve for hours last night and came up with this: https://code.sololearn.com/c9rIgUSY1nle/?ref=app I know it's not as much efficient as your. But kinda okayish. Edit: And it also fails many conditions like "999hello116her101" which outputs "chelloher". instead of "c9hellothere".
2nd Apr 2021, 4:31 AM
Carlos
Carlos - avatar
+ 1
Carlos, You're welcome It's also a nice topic for practice 👍
2nd Apr 2021, 6:56 AM
Ipang
0
Carlos, How far have you gone trying? Can you share your code in the Description above for a review? ☝
1st Apr 2021, 4:01 PM
Ipang
0
Hint : typecast it
3rd Apr 2021, 12:28 PM
Anjali Shaw
Anjali Shaw - avatar