Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53916

Re: a gift function and a question

From random832@fastmail.us
References <mailman.193.1378757469.5461.python-list@python.org> <522ec3c0$0$29999$c3e8da3$5496439d@news.astraweb.com>
Subject Re: a gift function and a question
Date 2013-09-10 09:50 -0400
Newsgroups comp.lang.python
Message-ID <mailman.210.1378821028.5461.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Sep 10, 2013, at 3:01, Steven D'Aprano wrote:
> def integerToPersian(number):
>     """Convert positive integers to Persian.
> 
>     >>> integerToPersian(3455)
>     '۳۴۵۵'
> 
>     Does not support negative numbers.
>     """
>     digit_map = dict(zip('0123456789', '۰۱۲۳۴۵۶۷۸۹'))
>     digits = [digit_map[c] for c in str(number)]
>     return ''.join(digits)

You can support negative numbers if you use digit_map.get(c,c).

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

a gift function and a question Mohsen Pahlevanzadeh <mohsen@pahlevanzadeh.org> - 2013-09-10 00:40 +0430
  Re: a gift function and a question Steven D'Aprano <steve@pearwood.info> - 2013-09-10 07:01 +0000
    Re: a gift function and a question random832@fastmail.us - 2013-09-10 09:50 -0400
    Re: a gift function and a question Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-10 15:11 +0000

csiph-web