Home > Net >  Can't we iterate over integer using map in python?
Can't we iterate over integer using map in python?

Time:01-01

Here, in line ans = list(map(int, num)) it's returning int object is not iterable. Can't we just change int number to list using map?

def plusOne(self, digits: List[int]) -> List[int]:
        # arr = [str(x) for x in digits]
        arr = list(map(str, digits))
        word = ''
        word = word.join(arr)
        num = int(word)
        num1 = num   1
        ans = list(map(int, num))
        return ans

CodePudding user response:

No map changes each element of a iterable. Integers are not iterable.

This can be achieved like this:

list(str(124))
  • Related