> res map (int, StudentGrades) but in Python 3.x map returns an iterator, so to get real list, it must be wrapped into list call: > res list (map (int, StudentGrades)) The later way works well in both version of Python. If the “expression” is a simple integer representation, Python converts the argument s to an integer. In Python 2.x map returns directly the list, so you may use. We then used type casting to convert the individual elements of the list into integer to get the list of integers as output. □ Python’s built-in eval(s) function parses the string argument s into a Python expression, runs it, and returns the result of the expression. In this code, we have first used the split() method to first convert the string into list. You can also use the eval() function in a list comprehension to convert a list of strings to a list of ints: a =
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |