← Back to Community
##### Hi. Me again
Profile icon
FARHEENPALAGIRI

Hey everyone. I have a not-so-slight issue. So for this code I'm writing, a three digit number is inputted, and if the digits are in ascending order the code outputs YES and if it is not, the code outputs NO. So I was trying to make the number into a list, do the thing where a variable was assigned to each item on the list, and then find out if the digits are in ascending order using an if/else statement, but then I realized my list was in string form. So, I tried to convert to integer form. I did this:

a = int(input())
num_list = list(str(a))
num_list_2 = map(int, num_list)
print(num_list_2)

But when I tried the print statement, I got an output of:

<map object at 0x7f1174cd6390>

What does this even mean? It's not even a syntax error. Does anyone know another way to turn the string list into an integer list? Please help.

Voters
Profile icon
FARHEENPALAGIRI
hotnewtop
Profile icon
Geocube101

You could just get the input and send it to an array: `a = list(input())` which should return the input as a list with each character as an element (You then need to iterate through and convert each element to an integer via `int()` method). From there, you can make another list and call the `sorted()` function to sort it. Compare the first list with the second sorted list and done! If they match, it should return `True`.

a = list(input())
for b in range(len(a)):
--a[b] = int(a[b])
c = sorted(a)
if a == c:
--print(True)
else:
--print(False)

#Dashed are representative of spaces

Profile icon
FARHEENPALAGIRI

@Geocube101 Thank you so much

Profile icon
ash15khng

You could do something like
`num_list_2 = [int(num) for num in num_list]`
This is called a list comprehension and is basically a shorter way of writing

```.css-19sk4h4{position:relative;}.css-1bu6gr6{-webkit-align-items:stretch;-webkit-box-align:stretch;-ms-flex-align:stretch;align-items:stretch;border-width:0;border-style:solid;box-sizing:border-box;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-basis:auto;-ms-flex-preferred-size:auto;flex-basis:auto;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;outline:none;min-height:0;min-width:0;position:relative;}.css-1n2m10r{padding:var(--space-8);border-radius:var(--border-radius-4);background-color:var(--background-higher);}.css-1hwur6u{-webkit-align-items:stretch;-webkit-box-align:stretch;-ms-flex-align:stretch;align-items:stretch;border-width:0;border-style:solid;box-sizing:border-box;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-basis:auto;-ms-flex-preferred-size:auto;flex-basis:auto;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;outline:none;min-height:0;min-width:0;padding:var(--space-8);border-radius:var(--border-radius-4);background-color:var(--background-higher);}.css-1ubbl1f{padding:var(--space-4);padding-left:var(--space-4);padding-right:var(--space-2);font-family:var(--font-family-code);font-size:14px;line-height:var(--line-height-small);overflow-x:auto;word-break:break-word;white-space:break-spaces;overflow-wrap:anywhere;}```num_list_2 = []
for num in num_list:
num_list_2.append(num)``````

If you want to use your code, change line 3 to `num_list_2 = list(map(int, num_list))`. `map()` returns a map object, not a list, so you need to turn in into a list by adding `list()` in front of it.

Profile icon
FARHEENPALAGIRI

@ash15khng Thanks a lot. So an array is like a list for integers, right?

Profile icon
HappyFakeboulde

AFAIK `map` doesn't return a `list`, it returns an iterator.
I could be wrong though 🤷.

Profile icon
FARHEENPALAGIRI

@HappyFakeboulde What's an iterator??

Profile icon
HappyFakeboulde
Profile icon
FARHEENPALAGIRI