3rd Aug 2020, 5:06 PM
Jayendra Todawat
Jayendra Todawat - avatar
13 Antworten
+ 11
The task can be done in a rather simple way: (1) take the input string and reverse it (2) create an empty list for final result (3) use a for loop to iterate over the input string (4) in for loop check if character from input string isalpha() or if it is a space (5) If yes: append this character to the final list (6) use final list and ''.join() elements and print the result
3rd Aug 2020, 8:04 PM
Lothar
Lothar - avatar
+ 13
How will we know the error without debugging and how will we debug when we don't have the code. Show us your attempt.
3rd Aug 2020, 5:09 PM
RKK
RKK - avatar
+ 11
ord(33) to ord(65) does not cover all the characters that must be skip. Why don't you reverse the process instead of finding characters which shouldn't be in output, why not instead find the ones that are needed to be shown as output(the alphabets) for example: finding only the alphabets instead REVERSING YOUR LOGIC: message=str(input()) mes=list(message) mes.reverse() mes1=[] for i in mes: if (ord(i) >= 65 and ord(i) <= 90) or (ord(i) >= 97 and ord(i) <= 122) or ord(i)==32: mes1.append(i) print(''.join(mes1)) ________________________________________ here's more improvement, why use list when we can achieve the same result using string message=str(input()) mes=list(message) mes1="" for i in mes: if (ord(i) >= 65 and ord(i) <= 90) or (ord(i) >= 97 and ord(i) <= 122) or ord(i)==32: mes1+=i print(mes1[::-1]) # "socat" is reversed here to our output - "tacos"
3rd Aug 2020, 5:38 PM
RKK
RKK - avatar
+ 9
Jayndra Todawat , post your code linked to Playground so somebody can help you.
3rd Aug 2020, 5:08 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 7
x=str(input()) a=[] b="".join(filter(lambda x:x.isalpha(),x)) for i in x: if i in b or i==" ": a.append(i) d="".join(a) print(d[::-1]) this is what lothar said
3rd Aug 2020, 8:55 PM
Agazi Birhanu
Agazi Birhanu - avatar
+ 6
Sorry guys Rohit TheWh¡teCat 🇧🇬 Blue_Ocean Here is my code n=0 message=str(input()) mes=list(message) mes.reverse() mes1=[] for i in mes: k=mes[n] j=ord(k) if j in range(33,65): mes.remove(k) else: mes1.append(k) n+=1 mes3=' '.join(mes1) print(mes3)
3rd Aug 2020, 5:17 PM
Jayendra Todawat
Jayendra Todawat - avatar
+ 6
Rohit Thanx
3rd Aug 2020, 5:39 PM
Jayendra Todawat
Jayendra Todawat - avatar
+ 6
Ayush Rastogi Yes bro its worked Thnx
4th Aug 2020, 1:17 AM
Jayendra Todawat
Jayendra Todawat - avatar
+ 6
Lothar Yes I have done it in the manner u say.. Thnx for help
4th Aug 2020, 1:18 AM
Jayendra Todawat
Jayendra Todawat - avatar
+ 5
Jayndra Todawat You forgot about space add this if k==' ': mes1.append(k) And modify this mes3=''. join(mes1) (no space)
3rd Aug 2020, 5:29 PM
v@msi😉
v@msi😉 - avatar
+ 5
v@msi😏😏 Thanks but It didn't work. I think I must change my logic
3rd Aug 2020, 5:36 PM
Jayendra Todawat
Jayendra Todawat - avatar
+ 5
s=input() x=s[::-1] st="" for i in range(len(x)): if x[i] in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ": st+=x[i] print(st) Try this.
3rd Aug 2020, 6:28 PM
Ayush Rastogi
Ayush Rastogi - avatar
- 1
Lol... 😂😂😂😂
4th Aug 2020, 1:15 PM
Ebenezer Noah
Ebenezer Noah - avatar