+ 1

Can it be more optimised?

Classment of multiples https://code.sololearn.com/c3AirizByeDE/?ref=app

11th Nov 2019, 10:10 AM
jeremy
7 Respostas
+ 3
You could replace lines: if i%2 == 0 : classment["even"].append(i) else : classment["odd"].append(i) With: if i&1: classment["odd"].append(i) else: classment["even"].append(i)
11th Nov 2019, 10:51 AM
Seb TheS
Seb TheS - avatar
+ 3
multiple = {} for i in range(2,10): multiple[i] = [] for j in range(0,20,i): multiple[i].append(j) print(multiple) You can improve it using a list comprehension. https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2454/
12th Nov 2019, 8:42 AM
Diego
Diego - avatar
+ 3
https://code.sololearn.com/c8AaWVXMjaNd
12th Nov 2019, 9:12 AM
David Ashton
David Ashton - avatar
+ 2
Thx Diego
12th Nov 2019, 8:48 AM
jeremy
+ 2
So beautiful code Louis and David
12th Nov 2019, 11:02 AM
jeremy
+ 1
Thx
11th Nov 2019, 11:02 AM
jeremy
+ 1
lim = 20 d = { i : list( range(0,lim,i) ) for i in range( 2,int(lim/2) )} print(d)
12th Nov 2019, 8:56 AM
Louis
Louis - avatar