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'
8 odpowiedzi
+ 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)
+ 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)
+ 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
+ 1
Ipang Bro Can You Please Tell me about f'"{c}'''
As I am a beginner
And Many Many Thanks for help🙂🙂
+ 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/
+ 1
Thanks Ipang
+ 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
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.