How to print the characters in the list in reversed format | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to print the characters in the list in reversed format

List contains characters and symbols

12th Apr 2019, 6:22 AM
Karthik Devillers
Karthik Devillers - avatar
6 Answers
+ 4
hi, you can use something like that: lst = [1, 2, 3, '?', '*', 'a', 'b', 'c'] for i in lst[::-1]: if str(i).isalnum(): print(i, end = '') # output = cba321
12th Apr 2019, 9:35 AM
Lothar
Lothar - avatar
+ 4
Like this? https://code.sololearn.com/c9vkx6q1ACpJ/?ref=app Otherwise if it's just the letters you need, you can just do something like: print(*reversed([l for l in list_ if l.isalpha()]))
12th Apr 2019, 9:57 AM
HonFu
HonFu - avatar
+ 2
It contains symbols too so have to reverse only the alphabets
12th Apr 2019, 6:37 AM
Karthik Devillers
Karthik Devillers - avatar
+ 2
Yeah
12th Apr 2019, 6:39 AM
Karthik Devillers
Karthik Devillers - avatar
+ 1
print(*reversed(your_list))
12th Apr 2019, 6:37 AM
HonFu
HonFu - avatar
+ 1
Ah okay. That's mildly trickier then. :)
12th Apr 2019, 6:38 AM
HonFu
HonFu - avatar