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).
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to