Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

This can be achieved like this:

list(str(124))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading