I have a string:
string = "Hello World"
That needs changing to:
"hello WORLD"
Using only split and join in Python.
Any help?
string = "Hello World" split_str = string.split()
Can't then work out how to get first word to lowercase second word to uppercase and join
OP's objective cannot be achieved just with split() and join(). Neither of those functions can be used to convert to upper- or lower-case.
The cycle class from the itertools module is ideal for this:
from itertools import cyclewords = 'hello world'CYCLE = cycle((str.lower, str.upper))print(*(next(CYCLE)(word) for word in words.split()))
Output:
hello WORLD