Spy Life Code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Spy Life Code

Hi! I’m having trouble with my code for the Spy Life challenge. Can someone tell me the issue in this code? import re input = input() output = re.sub(r"[^\w\s]", "", input) list = list(output) for i in list: if i == '1' or i == '2' or i == '3' or i == '4' or i == '5' or i == '6' or i == '7' or i == '8' or i == '9' or i == '0': list.remove(i) else: continue list.reverse() final = "".join(list) print(final)

11th Mar 2020, 1:58 AM
Eden
6 Answers
+ 13
David Ashton Thank you so much! With your advice, I came up with a new way to solve the problem that worked! input = input() list = [] for i in input: if i.isalpha(): list.append(i) elif i == " ": list.append(i) else: continue list.reverse() final = "".join(list) print(final)
11th Mar 2020, 4:18 PM
Eden
+ 12
OR!ON I agree with not simply providing the answer in lesson quiz comments and with not disclosing pro code coach questions. The code I wrote is set at private and does not disclose the code coach problem, which is not a pro question. Eden is pursuing a different approach, which I offered some suggestions for. I have not yet seen (although I have explicitly asked for) a definitive answer on this situation. I shared my particular creation, which approaches the problem from a different angle, in the spirit of helping others to learn to code, not helping them gobble up XP. If it is permissible to give a series of hints which make solving a code coach question easy for anyone reading the thread, I don't see a real difference. I'm open to being persuaded otherwise. 🙂
11th Mar 2020, 11:13 AM
David Ashton
David Ashton - avatar
+ 4
I don't see why it's failing the second test, but I don't use regex because I'm pretty weak in that area. Your 'if' statement could be a bit shorter, e g. if i in "124567890": or better - if i.isdigit(): Here's my code https://code.sololearn.com/cY9RGgh74WLj
11th Mar 2020, 7:26 AM
David Ashton
David Ashton - avatar
+ 2
David Ashton Directly providing solution?
11th Mar 2020, 8:49 AM
OR!ON 🛡️
OR!ON 🛡️ - avatar
+ 1
The second testcase is not being passed My output:youaregreat Expected output:you are great This is my code string=input() list1=[] i=0 length=len(string) while(i<length): for letter in range(97,123): if(string[i]==chr(letter)): temp=list1.append(chr(letter)) else: letter+=1 i+=1 str="" str1=str.join(list1[::-1]) print(str1)
1st Jun 2020, 3:02 PM
Akshaya Arunkumar
0
x = input() y = x[::-1] txt = "" for i in y: if i.isalpha() or i == " ": txt += i print(txt)
24th Sep 2021, 7:04 AM
Mateo González Bufi
Mateo González Bufi - avatar