+ 1
how can i have number=111 as a=[1,1,1] in python??( not['1','1','1'])
15 odpowiedzi
+ 1
#1. With function:
print((lambda num: list(map(int, str(num))))(111))
#2. Without function:
print([int(i) for i in str(111)])
#output: [1,1,1]
+ 5
a="111"
b=[]
for i in a:
b.append(int(i))
print(b)
+ 3
#from Petr
#variant convert list of number ro str by map()
a=[1,1,1]
print("".join(map(str,a)))
+ 2
a=[1,1,1]
print("".join([str(z) for z in a]))
+ 2
mahsa
variant 1: map()
https://code.sololearn.com/cXGJof0Q7koL/?ref=app
+ 2
mahsa
variant 2:. *list
https://code.sololearn.com/cEYnVKtgSv5H/?ref=app
+ 1
number = 111
a = [int(x) for x in list(str(number))]
print(a)
+ 1
wait, you want to convert 111 in [1,1,1]?
+ 1
Oh sorry 😅😅
+ 1
number = '111'
a = [char for char in number]
for index, value in enumerate(a):
a[index] = int(value)
print(a)
0
What? Down vote? Why?
0
@I×Am×Idiot
I think you've miss-understood the question. (or I have).
111 = one hundred and eleven to [1,1,1].
edit...just to clarify....It wasn't me that down-voted.
0
I×Am×Idiot yeah
0
n = 111
a = list(map(int, str(n)))