This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
string = u"page=/web/mini_f21/site/index.jsp,0.0,\ | |
pagetitle=博世家电-户外全能™系列洗衣机,\ | |
pagetag=,pagedomain=minisite.bosch-home.cn,|page=/virtual/主页,122.0,\ | |
pagetitle=博世家电-户外全能™系列洗衣机,pagetag=,\ | |
pagedomain=minisite.bosch-home.cn,|page=/web/mini_f21/site/index.jsp,36.0,\ | |
pagetitle=博世家电-户外全能™系列洗衣机,\ | |
pagetag=,pagedomain=minisite.bosch-home.cn,\ | |
|page=/virtual/主页,62.0,pagetitle=博世家电-户外全能™系列洗衣机,\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def knuthshuffle(a): | |
N = len(a) | |
for i in range(N): | |
r = random.randint(0,i+1) | |
temp = a[i] | |
a[i] = a[r] | |
a[r] = temp | |
if __name__ == "__main__": |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import copy | |
from copy import deepcopy | |
def isSorted(a): | |
for i in range(1,len(a)): | |
if(a[i]<a[i-1]): | |
return False | |
return True | |
def insertionSort(a): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def binarySearch(a,key): | |
lo =0 | |
hi = len(a) | |
while(lo<hi): | |
mid = lo + (hi-lo)/2 | |
if(key < a[mid]): | |
hi = mid-1 | |
elif(key >a[mid]): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WeightedQuickUnionUF(object): | |
def __init__(self,N): | |
self.__id = [] | |
self.sz = [] | |
for i in range(N): | |
self.__id.append(i) | |
self.sz.append(1) | |
def root(self,i): | |
while(i!=self.__id[i]): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class QuickUnionUF(object): | |
def __init__(self,N): | |
self.__id = [] | |
for i in range(N): | |
self.__id.append(i) | |
def root(self,i): | |
while(i!=self.__id[i]): | |
self.__id[i] = self.__id[self.__id[i]] | |
i = self.__id[i] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class QuickFindUF(object): | |
def __init__(self,N): | |
self.__id = [] | |
for i in range(N): | |
self.__id.append(i) | |
def connected(self,p,q): | |
return self.__id[p] == self.__id[q] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#code sample | |
# from wiki.python.org/moin/SimplePrograms | |
# "1 line: Output" | |
print "hello,world" | |
# 2 lines: input,assignment | |
name= raw_input('What is your name?\n') | |
print 'Hi %s.' % name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#descriptor example | |
class RevealAccess(object): | |
def __init__(self,initval=None,name='var'): | |
self.val = initval | |
self.name = name | |
def __get__(self,obj,objtype): | |
print "Retrieving",self.name | |
return self.val |