El miércoles, 3 de septiembre de 2014 05:27:29 UTC-7, c...@isbd.net  escribió:
> I know I can get a list of the characters in a string by simply doing:-
> 
> 
> 
>     listOfCharacters = list("This is a string")
> 
> 
> 
> ... but how do I get a list of integers?
> 
> 
> 
> -- 
> 
> Chris Green
> 
> ·

You Can Apply either, a map function or a list comprehension as follow:

Using Map:
>>> list(map(ord, listOfCharacters))
[84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 115, 116, 114, 105, 110, 103]

Using List Comprehension:

>>> [ord(n) for n in listOfCharacters]
[84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 115, 116, 114, 105, 110, 103]

Very Best Regards
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to