Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. ## This is the text editor interface.
  2. ## Anything you type or change here will be seen by the other person in real time.
  3.  
  4. def words(people, min, max):
  5. list = [0]*(max+2-min)
  6. for x in people:
  7. list[x[0]-min] += 1
  8. #print x[1]
  9. list[x[1]+1-min] -= 1
  10.  
  11. print list
  12. maxAlive = 0
  13. maxAliveYear = 0
  14. result = []
  15. Alive = 0
  16. for x in xrange(max-min+1):
  17. Alive += list[x]
  18. result.append((x, Alive))
  19. if Alive > maxAlive:
  20. maxAlive = Alive
  21. maxAliveYear = x+min
  22.  
  23. for p in people:
  24. print p[0], result[p[0]-min]
  25. print p[1], result[p[1]-min]
  26.  
  27. return maxAliveYear
  28.  
  29. people = [(1, 5), (2, 6), (3, 7)]
  30. #print words(people, 1, 7)
  31.  
  32.  
  33.  
  34. def matchString(input, given):
  35. dict = {}
  36. index = 0
  37. for x in xrange(0, len(given), 2):
  38. dict[given[x]] = [index, int(given[x+1])]
  39. index += 1
  40.  
  41. pseudo = 0
  42.  
  43. prev = input[0]
  44. if prev in dict:
  45. dict[input[0]][1] -= 1
  46. else:
  47. return False
  48. for x in xrange(1, len(input)):
  49. print dict[input[x]]
  50. if input[x] == prev and dict[input[x]][1] > 0:
  51. print input[x]
  52. prev = input[x]
  53. dict[input[x]][1] -= 1
  54. elif input[x]== prev and dict[input[x]][1] < 1:
  55. prev = input[x]
  56. return False
  57. elif input[x] in dict:
  58. pseudo += 1
  59. if dict[input[x]][1] > 0 and dict[input[x]][0] == pseudo:
  60. dict[input[x]][1] -= 1
  61. prev = input[x]
  62. else:
  63. return False
  64. else:
  65. return False
  66.  
  67. return True
  68.  
  69.  
  70.  
  71.  
  72.  
  73. #print matchString("aaabbb", "a3b4c4")
  74. import timeit
  75. start = timeit.default_timer()
  76.  
  77.  
  78. truedict = {}
  79. dict = { 'i', 'like', 'sam', 'sung', 'samsung', 'mobile', 'ice', 'cream', 'icecream','and', 'man', 'go', 'mango'}
  80. def checkSplit(word):
  81. if len(word)==0:
  82. return True
  83. if word in dict:
  84. truedict[word] = True
  85. if word in truedict:
  86. return True
  87. for x in xrange(len(word)+1):
  88. if word[:x] in dict and checkSplit(word[x:]):
  89. truedict[word] = True
  90. return True
  91.  
  92. return False
  93.  
  94. print checkSplit("samsungandmango")
  95.  
  96.  
  97. stop = timeit.default_timer()
  98. print stop - start
  99. #2.31266021729e-05
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. # input: "Connor Riley"
  108. # output: "[Co]nnor R[I]ley"
  109. # input: "Helen Keller"
  110. # output: "[He]len [K]eller"
  111. # takes a name as input
  112. # highlight any chemical element symbols
  113. # highlight one match per word
  114. # prefer longer matches
  115. # if there are no matches, just print out the input string
  116.  
  117.  
  118. dict = {"co", "n", "i", "le"}
  119. def findHigh(input):
  120. list = input.split()
  121. result = []
  122. for x in list:
  123. highlight = findLight(x)
  124. if(highlight):
  125. start_index = x.find(highlight)
  126. end_index = start_index + len(highlight)-1
  127. result.append(x[:start_index] + "[" + x[start_index:end_index+1] + "]" + x[end_index+1:])
  128. else:
  129. result.append(x)
  130.  
  131. return (" ").join(result)
  132.  
  133.  
  134.  
  135. def findLight(word):
  136. maxi = word
  137. lenmaxi = 0
  138. index = 0
  139. track = 0
  140. for element in dict:
  141. if element in word:
  142. track += 1
  143. if len(element) > lenmaxi:
  144. maxi = element
  145. lenmaxi = len(element)
  146.  
  147. if track > 0:
  148. return maxi
  149. return 0
  150.  
  151.  
  152. print findHigh("connor riley")
  153. print findHigh("helen keller")
  154.  
  155. #2.59876251221e-05
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement