Some useful Coding techniques

Some useful Coding techniques

Table of content

#Git

###Remove bad commit from remote

###Revert to some previous commit

###Remove files from Git but keep local copies

#Python

###Repeat a string

'this is a string' * 100

###Sort a list nums and return index

>>> nums=[1,2,3,4,2,2,1,2,3,2,1,2,3,4,5]
>>> ind = sorted(range(len(nums)), key = lambda x: nums[x])

###Iterate over a list with index and value

for i,v in enumerate(mylist):
  print i,v

###Pair up value in lists

for v1,v2 in zip(None,v1List,v2List):
  print v1,v2

###Product of lists

import itertools
for v1,v2 in list(itertools.product(v1List,v2List))
  print v1,v2 

pop()

  1. l.pop() is to get and remove the last item from the list.
  2. l.pop(i) is to get and remove the ith item from the list.
Hongyu Su 15 May 2015