0
What does this do? (Python)
print("".join(input().split()))
4 Respuestas
+ 8
The code is doing:
(1) asking for an input ( like 'hello world')
(2) this input will the be split at the position of spaces and stores it to a list: ['hello', 'world']
(3) join is taking this list and put the elementd of the list together to a string, using no space inbetween. helloworld
if '-'.joinn(..) is used this way, it will concatenate the elements of the list like hello-world
+ 4
Splits the string into a list of individual elements based on argument provided to split method and join those elements back to form a string based on argument passed to join method ,
For example:
a="hello world"
print(",".join(a.split())) will result in -> hello,world
+ 3
It removes gaps from a sentence.
IE:
this is a test => thisisatest