can it be shorter?

Brian Brian.Mingus at colorado.edu
Sun Jun 7 18:59:36 EDT 2009


Since extra slashes at the end of a URL are ignored, that means I win!

url+='/'

On Sun, Jun 7, 2009 at 4:45 PM, Aaron Brady <castironpi at gmail.com> wrote:

> 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.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090607/ff0d73e0/attachment-0001.html>


More information about the Python-list mailing list