Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have an integer object for example a = 1234 and I want to convert it to a list, so it would look something like [1234].
I tried converting it into a string first and then converting it to a list but that gives me [1,2,3,4]. Any suggestions?
[a]
You can just cover it in brackets.
a = 1234 print([a])
Or append()
append()
b = [] b.append(a)
output
[1234]
Add a comment
Here:
a = 1234 lst = [] lst.append(a) print(lst) #[1234]
Just cover it with brackets:
a=1243 a=[a]
or create a list and append a
b = [] b.append(a) # or you could do b=[a]
If you are trying to put your int in a list, use []:
[]
>>> var = 1234 >>> [var] [1234]
or do:
>>> l = [] >>> l.append(var) >>> l [1234]
Well it depends. If you need the int to be a single member of a list then [a] works. If you need each digit in the integer to be an individual member of the list then list(str(a)) will work for you.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
[a]will make a list.