Hey guys,

Hope you all are doing great. I love Code Golfing, what it brings out in you is the hidden concepts of a programming language and especially the push to implement same thing in numerous ways.

Code Golfing and Python - Yeah that's my Poison!

Below are few tips and tricks which will give you an edge over other programmer to write the shortest code:

1. The foo if condition else bar condition can be shortened to
                   
 True if condition else False   ------- [False,True][condition]

2. Convert long range rifle to pistol: range to an small format
                   
 for i in range(n) ------ for i in [1]*n

3. String input in Python2 vs String input in Python3:
                    string = raw_input()           vs            string  = input()

4. For Python2 convert datatype to string:

 str(variable) ------ `variable`   
 The grave(`) sign near top left of your keyboard

5.Remove unnecessary spaces(' '):

'Goku' if dragon_balls == 9 else 3PO ----- 'Goku'if dragon_balls==9else3PO


Please let me know your feedback, on how i can improve and make it better. Till then!! Cheers!!
0

Add a comment

print ("About Me")
print ("About Me")
My Photo
HYDERABAD, Telangana, India
Blog.History(All)
Labels
About Me
About Me
Loading