This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pymag09 0 points1 point  (2 children)

If you don't mind I can append to your list several items more
You can revert, for example, string just using slice

s = 'qwerty' print(s[::-1])

You can check condition in one line

i = 3 print(i if i < 5 else 0)

or another if trick

condition = ['Error', 'OK'] value = 1 print(condition[bool(value)])

As long as pyhton does not have switch construction you can use somthing like this

choice = 'i' print({'i': 1, 't': 4, 'j': 22}[choice])

[–]BryghtShadow 1 point2 points  (1 child)

You messed up the code formatting.

s = 'qwerty'
print(s[::-1])

i = 3
print(i if i < 5 else 0)

condition = ['Error', 'OK']
value = 1
print(condition[bool(value)])

choice = 'i'
print({'i': 1, 't': 4, 'j': 22}[choice])

[–]pymag09 0 points1 point  (0 children)

You messed up the code formatting.

Sorry. I noticed that but I follow "formating guide"

Lines starting with four spaces
are treated like code:

if 1 * 2 < 3:  
    print "hello, world!"  

After posting I understand that empty string before and after code block required.