Pattern Search Regular Expression
Joshua Landau
joshua.landau.ws at gmail.com
Sat Jun 15 17:03:19 EDT 2013
On 15 June 2013 11:18, Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
> I tend to reach for string methods rather than an RE so will something like
> this suit you?
>
> c:\Users\Mark\MyPython>type a.py
> for s in ("In the ocean",
> "On the ocean",
> "By the ocean",
> "In this group",
> "In this group",
> "By the new group"):
> print(' '.join(s.split()[1:-1]))
>
>
> c:\Users\Mark\MyPython>a
> the
> the
> the
> this
> this
> the new
Careful - " ".join(s.split()) != s
Eg:
>>> " ".join("s\ns".split())
's s'
It's pedantry, but true.
More information about the Python-list
mailing list