print('a b c d e f g h i j k l m n o p q r s t u v w x y z').replace(' ', '', '') How can I Replace space with ',' in Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

print('a b c d e f g h i j k l m n o p q r s t u v w x y z').replace(' ', '', '') How can I Replace space with ',' in Python

I want this Input= a b c.... x y z Output='a','b',......,'z'

15th Jun 2020, 3:32 AM
M.A. Masud Karim Nayeem
8 Answers
+ 7
my_string = ",".join([f"'{c}'" for c in 'a b c d e f g h i j k l m n o p q r s t u v w x y z'.split(' ')]) print(my_string)
15th Jun 2020, 3:44 AM
Ipang
+ 3
Try this, a = ('a b c d e f g h i j k l m n o p q r s t u v w x y z') a = a.replace(' ', ',') print(a)
15th Jun 2020, 3:35 AM
M Tamim
M Tamim - avatar
+ 1
Bro It's output will be a,b,c, .....z I need output 'a','b','c'.....,'z' M Tamim see the question Carefully Before Answer a Question
15th Jun 2020, 3:40 AM
M.A. Masud Karim Nayeem
+ 1
Ipang Bro Can You Please Tell me about f'"{c}''' As I am a beginner And Many Many Thanks for help🙂🙂
15th Jun 2020, 3:49 AM
M.A. Masud Karim Nayeem
+ 1
It is called string interpolation (hope I wrote it right). You can read about its intro here bro M.A. Masud Karim Nayeem 👇 https://realpython.com/JUMP_LINK__&&__python__&&__JUMP_LINK-f-strings/
15th Jun 2020, 3:53 AM
Ipang
+ 1
Thanks Ipang
15th Jun 2020, 3:55 AM
M.A. Masud Karim Nayeem
+ 1
You can do that with regular expression with the sub method. Like this: import re txt = "a b c d" pattern = r" " replace = re.sub(pattern, ",", txt) https://code.sololearn.com/c4kKgLmkd0Yz/?ref=app
16th Jun 2020, 8:21 PM
arieh
0
Try this: letter = [#listAllTheLetterHere] for i in range(len(letter)): print("'{0}'".format(letter[i]), end = ',') print(letter[-1] Just another different perspective. Sorry for inconvenience.
15th Jun 2020, 4:58 PM
Shazwan X-99
Shazwan X-99 - avatar