can it be shorter?

Aaron Brady castironpi at gmail.com
Sun Jun 7 18:45:09 EDT 2009


On Jun 6, 8:07 am, "tsangpo" <tsangpo.newsgr... at gmail.com> wrote:
> I want to ensure that the url ends with a '/', now I have to do thisa like
> below.
> url = url + '' if url[-1] == '/' else '/'
>
> Is there a better way?

url+= { '/': '' }.get( url[ -1 ], '/' )

Shorter is always better.



More information about the Python-list mailing list