Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## This is the text editor interface.
- ## Anything you type or change here will be seen by the other person in real time.
- def words(people, min, max):
- list = [0]*(max+2-min)
- for x in people:
- list[x[0]-min] += 1
- #print x[1]
- list[x[1]+1-min] -= 1
- print list
- maxAlive = 0
- maxAliveYear = 0
- result = []
- Alive = 0
- for x in xrange(max-min+1):
- Alive += list[x]
- result.append((x, Alive))
- if Alive > maxAlive:
- maxAlive = Alive
- maxAliveYear = x+min
- for p in people:
- print p[0], result[p[0]-min]
- print p[1], result[p[1]-min]
- return maxAliveYear
- people = [(1, 5), (2, 6), (3, 7)]
- #print words(people, 1, 7)
- def matchString(input, given):
- dict = {}
- index = 0
- for x in xrange(0, len(given), 2):
- dict[given[x]] = [index, int(given[x+1])]
- index += 1
- pseudo = 0
- prev = input[0]
- if prev in dict:
- dict[input[0]][1] -= 1
- else:
- return False
- for x in xrange(1, len(input)):
- print dict[input[x]]
- if input[x] == prev and dict[input[x]][1] > 0:
- print input[x]
- prev = input[x]
- dict[input[x]][1] -= 1
- elif input[x]== prev and dict[input[x]][1] < 1:
- prev = input[x]
- return False
- elif input[x] in dict:
- pseudo += 1
- if dict[input[x]][1] > 0 and dict[input[x]][0] == pseudo:
- dict[input[x]][1] -= 1
- prev = input[x]
- else:
- return False
- else:
- return False
- return True
- #print matchString("aaabbb", "a3b4c4")
- import timeit
- start = timeit.default_timer()
- truedict = {}
- dict = { 'i', 'like', 'sam', 'sung', 'samsung', 'mobile', 'ice', 'cream', 'icecream','and', 'man', 'go', 'mango'}
- def checkSplit(word):
- if len(word)==0:
- return True
- if word in dict:
- truedict[word] = True
- if word in truedict:
- return True
- for x in xrange(len(word)+1):
- if word[:x] in dict and checkSplit(word[x:]):
- truedict[word] = True
- return True
- return False
- print checkSplit("samsungandmango")
- stop = timeit.default_timer()
- print stop - start
- #2.31266021729e-05
- # input: "Connor Riley"
- # output: "[Co]nnor R[I]ley"
- # input: "Helen Keller"
- # output: "[He]len [K]eller"
- # takes a name as input
- # highlight any chemical element symbols
- # highlight one match per word
- # prefer longer matches
- # if there are no matches, just print out the input string
- dict = {"co", "n", "i", "le"}
- def findHigh(input):
- list = input.split()
- result = []
- for x in list:
- highlight = findLight(x)
- if(highlight):
- start_index = x.find(highlight)
- end_index = start_index + len(highlight)-1
- result.append(x[:start_index] + "[" + x[start_index:end_index+1] + "]" + x[end_index+1:])
- else:
- result.append(x)
- return (" ").join(result)
- def findLight(word):
- maxi = word
- lenmaxi = 0
- index = 0
- track = 0
- for element in dict:
- if element in word:
- track += 1
- if len(element) > lenmaxi:
- maxi = element
- lenmaxi = len(element)
- if track > 0:
- return maxi
- return 0
- print findHigh("connor riley")
- print findHigh("helen keller")
- #2.59876251221e-05
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement