0

What does this do? (Python)

print("".join(input().split()))

20th Jul 2020, 7:05 PM
3.14
3.14 - avatar
4 ответов
+ 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
20th Jul 2020, 7:17 PM
Lothar
Lothar - avatar
+ 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
20th Jul 2020, 7:12 PM
Abhay
Abhay - avatar
+ 3
It removes gaps from a sentence. IE: this is a test => thisisatest
20th Jul 2020, 7:13 PM
Rik Wittkopp
Rik Wittkopp - avatar