Reputation: 811
I'm trying to convert characters in string into ascii value in Python
Like ord('a[i]') but ord expects only character not string!!
Is there any other method to solve this problem in python .
Upvotes: 2
Views: 5634
Reputation: 62123
An alternative to Sven's answer:
[ord(c) for c in s]
... or the corresponding generator expression:
(ord(c) for c in s)
Upvotes: 3
Reputation: 602705
>>> s = "string"
>>> map(ord, s)
[115, 116, 114, 105, 110, 103]
Upvotes: 9