Arun Kumar Arun Kumar - 4 months ago 6x
Python Question

Converting range of numbers with respective ASCII codes

How do i convert a set of values with its characters

every number in the range should be converted and returned

without using control statements and loops

Eg: range(97,100) should be converted to {'a','b','c'}


Try this:

>>> map(chr, range(97,100))
['a', 'b', 'c']

Use of char:

>>> chr(97)

Using list comprehension:

>>> [chr(x) for x in range(97,100)]
['a', 'b', 'c']

To get in unicode use unichr:

>>> [unichr(x) for x in range(97,100)]
[u'a', u'b', u'c']