Advertisement
jspill

webinar-exam-review-2022-03-26

Mar 26th, 2022
1,391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.91 KB | None | 0 0
  1. # Exam Review 2022 Mar 26
  2.  
  3. # LABS
  4. # Ch 3-13... all Labs!
  5. # Ch 14-18 not as important, other than some good labs in Ch 15
  6. # Ch 19-30 just LABS, but important practice!
  7. # Use Submit Mode!!!
  8.  
  9. # Comp 1: Basic syntax and knowledge: operators, data types, etc
  10. # Comp 2: Control Flow Structures
  11. # Basic: if statements, loops, functions
  12. # Adv: try/except and raising errors, classes
  13. # Comp 3: modules, working with files
  14.  
  15. # Comp 1 Basic syntax and knowledge: operators, data types, etc
  16. # Data Types
  17. # int
  18. # float
  19. # str # strings
  20. # list
  21. # dict
  22. # bool
  23. # tuple # return x, y, z
  24. # set # unordered, all unique values
  25.  
  26. # input() # returns a str
  27. # # whitespace: " ", many Unicode variations, \r, \n, \t, \f
  28. # myVar = input().strip() # or input().rstrip()
  29. # myInt = int(input().strip())
  30. # myList = input().strip().split(",") # if not splitting on default any whitespace
  31.  
  32. # Operators
  33. # +
  34. # -
  35. # *
  36. # /
  37. # % # modulo!
  38. # // # floor divison!
  39. # ** # raise to a power, compare to math.pow()
  40. # <
  41. # >
  42. # <=
  43. # >=
  44. # = # assignment
  45. # == # asking
  46. # !=
  47. # +=
  48. # -=
  49. # # operator-like keyword
  50. # and
  51. # or
  52. # in # if __ in _someContainer_
  53. # not # if not __ in _someContainer__
  54.  
  55. # Comp 2 Control Flow Structures
  56. # Basic
  57. # IF statements: if, if/else, if/elif, if/elif/else
  58. # LOOPS
  59. # WHILE - basically an IF that repeats
  60. # FOR - loop over a container, or some known number of times with range()
  61. # for __ in __:
  62. # for item in _someContainer_:
  63. # for item in myList:
  64. # for i in range(len(myList)): # myList[i], myStr[i]
  65.  
  66. # FUNCTIONS
  67. # defining/writing vs calling
  68. # parameters vs "regular" variables
  69. # parameters vs arguments
  70. # methods are functions that "belong" to a type
  71. # a good function has ONE JOB, modular
  72. # return vs print()
  73.  
  74. # def checkDuplicates(someList):
  75.     # someList = # no! don't do this... the CALLS provide values
  76.  
  77. # lab question from Ch 7
  78. # print('{:.2f}'.format(driving_cost(10, mpg, dpg)))
  79. # print('{:.2f}'.format(driving_cost(50, mpg, dpg)))
  80. # print('{:.2f}'.format(driving_cost(400, mpg, dpg)))
  81.  
  82. # BUILT-IN FUNCTIONS
  83. # print()
  84. # input()
  85. # len()
  86. # min()
  87. # max()
  88. # sum()
  89. # sorted()
  90. # reversed()
  91. # range()
  92. # open()
  93. # round() # has 2 cousins in math: math.ceil(), math.floor()
  94. # constructor/recasting functions
  95. # int()
  96. # float()
  97. # list()
  98. # dict()
  99. # str()
  100. # set()
  101. # help() # you can use help() and dir() in the exam!
  102. # dir()
  103.  
  104. # STRINGS
  105. myString = "Just sit right back and you'll hear a tale."
  106. # SLICING strings and list
  107. # myString = myString[start, stop]
  108. # revString = myString[::-1]
  109.  
  110. # STRING METHODS
  111. # for item in dir(str):
  112. #     if not item.startswith("_"):
  113. #         print ("{}()".format(item))
  114. # myString.format()
  115. # myString.strip(), myString.rstrip()
  116. # myString.split() # returns a list of smaller strings
  117. # " ".join(listOfStrings)
  118. # myString.replace(someStr, newStr) # to remove.. myString(someSub, "")
  119. # myString.count(subStr) # return int
  120. # myString.find(subStr) # returns int index
  121. # case methods: myString.upper(), myString.lower()
  122. # Boolean/is methods: myString.isupper(), myString.isdigit()
  123.  
  124. # LIST METHODS
  125. # +
  126. # myList.append(item)
  127. # myList.insert(i, item)
  128. # myList.extend(anotherList)
  129. # # -
  130. # myList.pop() # by index
  131. # myList.remove() # by value
  132. #
  133. # myList.reverse()
  134. # myList.sort()
  135. # myList.count(item)
  136.  
  137. # DICTIONARIES
  138. # myDictionary[key] # retrieve value for that key
  139. # myDictionary[key] = value # kinda takes the place of update()
  140. # for _key_ in someDictionary: # IN looks at the keys
  141. #     # or for k, v in someDictionary.item():
  142. # if _key_ in thisDictionary:
  143. # myDictionary.keys()
  144. # myDictionary.values()
  145.  
  146. # SETS
  147. # mySet.add()
  148. # mySet.remove() # by value
  149. # mySet.pop() # removes a random entry!
  150.  
  151. # MATH MODULE
  152. # import math
  153. # math.e
  154. # math.pi
  155. # math.ceil()
  156. # math.floor()
  157. # math.sqrt()
  158. # math.pow() # **, not to be confused with math.exp()
  159. # math.factorial()
  160.  
  161. # full vs partial import
  162. # from math import factorial #... factorial() not math.factorial()
  163.  
  164. # # aliased import
  165. # import math as m #... m.factorial(), m.e
  166.  
  167. # # OPENING FILES
  168. # good practice: Ch 12 Task 4, 7, 8
  169. # I'll include these webinars in our follow up
  170.  
  171. # with open("filename.txt", "r") as f:
  172. #     myContent = f.readlines() # returns a list of line by line strings
  173.  
  174. # import csv
  175. # with open("mock_data.csv", "r") as f:
  176. #     myReader = list(csv.reader(f))
  177. # print(myReader)
  178. # for line in myReader:
  179. #     # print(line[2])
  180. #     print("{} is at {}".format(line[3], line[4]))  # then we can get at positions within the line
  181.  
  182. # student questions
  183. # Lab 31.21
  184. import csv
  185.  
  186. # Type your code here.
  187. filename = input().rstrip()
  188. wordList = []
  189.  
  190. with open(filename, "r") as f:
  191.     ufList = list(csv.reader(f))  # optional arg delimiter="\t"
  192.  
  193. # print(ufList)
  194. for row in ufList:
  195.     for word in row:
  196.         if word not in wordList:
  197.             print("{} {}".format(word, row.count(word)))  # here's where I missed the right paren of print() smh
  198.             wordList.append(word)
  199.            
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement