Arun Kumar Arun Kumar - 1 year ago 67
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'}

Answer Source

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']
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download