Python programming: add spaces between characters in a split line

I have to print every third letter of the text with spaces between them and not a single one at the end. I can do everything except spaces between each letter.

Here is what I have.

line = input('Message? ')                                          
print(line[0]+line[3::3].strip())
+4
source share
2 answers

To combine things with spaces, use join(). Consider the following:

>>> line = '0123456789'
>>> ' '.join(line[::3])
'0 3 6 9'
+7
source

Python 3, * print(), . line[0] - ([0::3]), ([::3]). , strip(), , Enter, input().

print(*input('Message? ')[::3])
-2

Source: https://habr.com/ru/post/1613925/


All Articles