+ 1

how can i have number=111 as a=[1,1,1] in python??( not['1','1','1'])

18th May 2020, 9:02 PM
mahsa
mahsa - avatar
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]
19th May 2020, 3:55 PM
Jenson Y
+ 5
a="111" b=[] for i in a: b.append(int(i)) print(b)
18th May 2020, 9:06 PM
Abhay
Abhay - avatar
+ 3
#from Petr #variant convert list of number ro str by map() a=[1,1,1] print("".join(map(str,a)))
20th May 2020, 5:52 PM
Devarinti.Venumadav
Devarinti.Venumadav - avatar
+ 2
a=[1,1,1] print("".join([str(z) for z in a]))
18th May 2020, 9:16 PM
4lx
4lx - avatar
18th May 2020, 9:29 PM
Petr
18th May 2020, 9:41 PM
Petr
+ 1
number = 111 a = [int(x) for x in list(str(number))] print(a)
18th May 2020, 9:25 PM
rodwynnejones
rodwynnejones - avatar
+ 1
wait, you want to convert 111 in [1,1,1]?
18th May 2020, 9:49 PM
4lx
4lx - avatar
+ 1
Oh sorry 😅😅
18th May 2020, 9:50 PM
4lx
4lx - avatar
+ 1
number = '111' a = [char for char in number] for index, value in enumerate(a): a[index] = int(value) print(a)
20th May 2020, 2:27 AM
Md. Niamul Ahad Chowdhury
Md. Niamul Ahad Chowdhury - avatar
0
What? Down vote? Why?
18th May 2020, 9:34 PM
4lx
4lx - avatar
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.
18th May 2020, 9:46 PM
rodwynnejones
rodwynnejones - avatar
18th May 2020, 9:49 PM
mahsa
mahsa - avatar
0
n = 111 a = list(map(int, str(n)))
19th May 2020, 4:11 AM
Bilbo Baggins
Bilbo Baggins - avatar