+ 20

Good Style - bad Style

One Question was to add '3' on the first and the plast position of an integer. My solution is: a = 253 b = len(str(a)) c = 10**(b+1) print (c*3+a*10+3) The same code is possible as an oneliner: print ((3*10**((int(len(str(253)))+1)))+253*10+3) But who can read and understand this? What do you think is the better way to write this code down?

26th Dec 2017, 2:25 PM
Sebastian Keßler
Sebastian Keßler - avatar
5 Réponses
+ 7
Oneliners are mostly difficult to understand. In my view, the only advantage of it is when you need to impress someone ;)
26th Dec 2017, 2:37 PM
Dev
Dev - avatar
+ 14
(i use oneliners on eval/exec)
26th Dec 2017, 2:51 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 7
@Sebastian: I don't think so. The decrease/increase in performance depends on the no. of calculations or operations you do in your code. That's what I recall...
27th Dec 2017, 5:39 AM
Dev
Dev - avatar
+ 3
ofcourse the first one is way better than the second !
26th Dec 2017, 2:33 PM
M.Amin.D
M.Amin.D - avatar
+ 2
Thanks. By the way: has the number of lines an effect on the performance of the Code?
26th Dec 2017, 9:05 PM
Sebastian Keßler
Sebastian Keßler - avatar