can it be shorter?
MRAB
python at mrabarnett.plus.com
Mon Jun 8 11:50:12 EDT 2009
Jean-Michel Pichavant wrote:
> Aaron Brady wrote:
>> Shorter is always better.
>> url+= { '/': '' }.get( url[ -1 ], '/' )
>
> Why bother with spaces or 3 letter-wide token, check this :o) :
> x+={'/':''}.get(x[-1],'/')
>
Even shorter:
x+='/'*(x[-1]!='/')
> Apart from joking, the following proposed solution is by **far** the one
> I prefer
>
>> if not url.endswith('/'):
>> url += '/'
>
> Maybe not the shorter, but the most concise and clear to me.
>
Definitely.
More information about the Python-list
mailing list