DEV Community

Discussion on: tips for python short code part-1

Collapse
 
xtofl profile image
xtofl

Also, when you'd need to append 'a lot' to the same list, you could shortcut k+=[1] to a=k.append; now you can a(1). (save 2 chars per append; becomes profitable when you need N appends where N*len('k+=[]')>len('a=k.append')+N*len('a()') <=> N>5)

k+=[1]
k+=[2]
k+=[3]
k+=[4]
k+=[5]
Enter fullscreen mode Exit fullscreen mode

vs

a=k.append
a(1)
a(2)
a(3)
a(4)
a(5)
Enter fullscreen mode Exit fullscreen mode

Now I'm having fun :)