List of python tips
- Reverse a string or list
- Reverse by custom step
- List slice assignment
- Check file or directory exists
- Call an external command
- Ternary conditional operator
list = ['a','b','c','d','e']
reverse_list = list[::-1]
string = "python"
print string[::-1]list = ['a','b','c','d','e']
reverse_list = list[::-2] list = ['a','b','c','d','e']
list[3:] = ['x','y','z']
print list
#output : ['a', 'b', 'c', 'x', 'y', 'z']os.path.isfile used only for files
import os.path
os.path.isfile(filename) # True if file exists
os.path.isfile(dirname) # False if direcoty existsos.path.exists used for both files and directories
import os.path
os.path.exists(filename) # True if file exists
os.path.exists(dirname) #True if directory existsfrom subprocess import call
call(['ls,'-l'])print 'True' if True else 'False'