Ignacio Cuevas
Ignacio Cuevas

Reputation: 3

Python put list of int as character numbers

I'm trying that at one point turns a list of integers and turns them into characters, then strings. For example:

items = [10, 20, 42]

If the three integers 10, 20, and 42 were given, I'd want to do change it into something that works in the sense of:

items = [chr(10), chr(20), chr(42)]
print(" ".join(items))

or:

items = chr(items)
print(" ".join(items))

But the second one does not work... and I need a way to do it that works if the number of items on the list is not always the same.

Upvotes: 0

Views: 362

Answers (2)

helloV
helloV

Reputation: 52403

Use map and chr

''.join(map(chr, items))

Upvotes: 1

zero323
zero323

Reputation: 330203

You easily use comprehension like this one:

" ".join(chr(x) for x in items)

Upvotes: 1

Related Questions