Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41598

Re: join()

From Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
Subject Re: join()
Date 2013-03-20 14:34 +0000
References <6110d82b-fce9-4146-8fcc-3276334a8f5f@14g2000vbr.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.3565.1363790118.2939.python-list@python.org> (permalink)

Show all headers | View raw


franzferdinand <melo.dumoulin <at> hotmail.com> writes:

> 
> 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
> 

I guess you mean: how can I re-generate a string from my list of sub-strings,
where each element is separated by only a single space.

' '.join(raw.split())

join is a string method that can take a list of strings to join as its argument.
Best,
Wolfgang



Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

join() franzferdinand <melo.dumoulin@hotmail.com> - 2013-03-20 07:05 -0700
  Re: join() Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2013-03-20 14:34 +0000
  Re: join() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-20 14:39 +0000
    Re: join() Tim Chase <python.list@tim.thechases.com> - 2013-03-20 10:54 -0500
      Re: join() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-20 18:44 +0000
  Re: join() Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-03-20 14:44 +0000
    Re: join() franzferdinand <melo.dumoulin@hotmail.com> - 2013-03-20 07:46 -0700

csiph-web