join()

Mark Lawrence breamoreboy at yahoo.co.uk
Wed Mar 20 10:44:32 EDT 2013


On 20/03/2013 14:05, franzferdinand wrote:
> I'm doing this "Write code that removes whitespace at the beginning
> and end of a string, and normalizes whitespace between words to be a
> single space character"
>
> I can do it using split()
>
>>>> raw = "      the     weather is     sunny                  today       "
>>>> raw.split()
> ['the', 'weather', 'is', 'sunny', 'today']
>
> But how do I do it using join() ?? Thanks
>

' '.join(raw.split())

-- 
Cheers.

Mark Lawrence




More information about the Python-list mailing list