Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I'm trying to map a list into hex, and then use the list elsewhere. In Python 2.6, this was easy:

A: Python 2.6:

>>> map(chr, [66, 53, 0, 94]) ['B', '5', '\x00', '^']

However, in Python 3.1, the above returns a map object.

B: Python 3.1:

>>> map(chr, [66, 53, 0, 94]) <map object at 0x00AF5570>

How do I retrieve the mapped list (as in A above) on Python 3.x?

Alternatively, is there a better way of doing this? My initial list object has around 45 items and I'd like to convert them to hex.

1 Answer

0 votes
by (106k points)
For Getting a map() to return a list in Python 3+, you can use the following method, there are many processes that iterate over iterables return iterators themselves. In most of the cases, this ends up saving memory, and it makes things go faster.
 list(map(chr,[66,53,0,94]))

image

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 29, 2019 in Python by Rajesh Malhotra (19.9k points)
0 votes
1 answer
0 votes
4 answers
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...