Double char - python
Solution 1:
This works great and is readable.
string = "Hello World"
final = ""
for char in string:
final += char*2
Solution 2:
You could do:
s = "Hello World"
print("".join(x*2 if x != " " else x for x in s ))
OUTPUT
'HHeelllloo WWoorrlldd'
I received a comment highlighting the fact that spaces do not need to be doubled - hence if x != " " else x
has been added. If that is not the case - you want to double spaces as well:
"".join(x*2 for x in s )