.split() Qeustion

Joshua Landau joshua at landau.ws
Wed Aug 14 07:55:23 EDT 2013


On 14 August 2013 12:45, Peter Otten <__peter__ at web.de> wrote:
> Joshua Landau wrote:
>> On 14 August 2013 09:30, Alister <alister.ware at ntlworld.com> wrote:
>>> I would agree with the last statement.
>>> Please write list definitions as lists rather than taking a short-cut to
>>> save a few key presses
>>
>> That's true with this example, but is:
>>
>> lines = [
>>     "Developments in high-speed rail, and high-speed",
> ...
>>     "same problems the latter was designed to solve."
>> ]
>>
>> really more readable than:
>>
>> lines = """\
>> Developments in high-speed rail, and high-speed
> ...
>> same problems the latter was designed to solve.
>> """[1:-1].split("\n")
>>
>> ?
>
> It's definitely more correct -- unless you meant to strip the "D" from the
> first line ;)
>
> I would use
>
> lines = """\
> Developments in high-speed rail, and high-speed
> ...
> same problems the latter was designed to solve.
> """.splitlines()

Thanks, I didn't actually know about .splitlines()!



More information about the Python-list mailing list