+ 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?

9th Aug 2021, 5:36 AM
sid
sid - avatar
3 Respostas
+ 9
Doubled = [number * 2**i for i in range(21)]
9th Aug 2021, 5:42 AM
你知道規則,我也是
你知道規則,我也是 - avatar
9th Aug 2021, 11:18 AM
Lothar
Lothar - avatar
0
CarrieForle (怎麼這麼多學生帳號?) Thanks.Really appreciates this. #StaySafe !
9th Aug 2021, 5:52 AM
sid
sid - avatar