+ 2
List comprehension Inplace change!
If i have a number and i want to double it on the every index of a list. Eg: number: 10 Array size will be: 20 Doubled=[number*i for i in range (1,21)] Above code produce [10,20,30,40....] But i want it to be [10,20,40,80,160]. How can i achieve this?
3 Respostas
+ 9
Doubled = [number * 2**i for i in range(21)]
+ 4
CarrieForle (怎麼這麼多學生帳號?) ,
this is perfect !!!
0
CarrieForle (怎麼這麼多學生帳號?) Thanks.Really appreciates this.
#StaySafe !