Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Exam Review 2022 Mar 26
- # LABS
- # Ch 3-13... all Labs!
- # Ch 14-18 not as important, other than some good labs in Ch 15
- # Ch 19-30 just LABS, but important practice!
- # Use Submit Mode!!!
- # Comp 1: Basic syntax and knowledge: operators, data types, etc
- # Comp 2: Control Flow Structures
- # Basic: if statements, loops, functions
- # Adv: try/except and raising errors, classes
- # Comp 3: modules, working with files
- # Comp 1 Basic syntax and knowledge: operators, data types, etc
- # Data Types
- # int
- # float
- # str # strings
- # list
- # dict
- # bool
- # tuple # return x, y, z
- # set # unordered, all unique values
- # input() # returns a str
- # # whitespace: " ", many Unicode variations, \r, \n, \t, \f
- # myVar = input().strip() # or input().rstrip()
- # myInt = int(input().strip())
- # myList = input().strip().split(",") # if not splitting on default any whitespace
- # Operators
- # +
- # -
- # *
- # /
- # % # modulo!
- # // # floor divison!
- # ** # raise to a power, compare to math.pow()
- # <
- # >
- # <=
- # >=
- # = # assignment
- # == # asking
- # !=
- # +=
- # -=
- # # operator-like keyword
- # and
- # or
- # in # if __ in _someContainer_
- # not # if not __ in _someContainer__
- # Comp 2 Control Flow Structures
- # Basic
- # IF statements: if, if/else, if/elif, if/elif/else
- # LOOPS
- # WHILE - basically an IF that repeats
- # FOR - loop over a container, or some known number of times with range()
- # for __ in __:
- # for item in _someContainer_:
- # for item in myList:
- # for i in range(len(myList)): # myList[i], myStr[i]
- # FUNCTIONS
- # defining/writing vs calling
- # parameters vs "regular" variables
- # parameters vs arguments
- # methods are functions that "belong" to a type
- # a good function has ONE JOB, modular
- # return vs print()
- # def checkDuplicates(someList):
- # someList = # no! don't do this... the CALLS provide values
- # lab question from Ch 7
- # print('{:.2f}'.format(driving_cost(10, mpg, dpg)))
- # print('{:.2f}'.format(driving_cost(50, mpg, dpg)))
- # print('{:.2f}'.format(driving_cost(400, mpg, dpg)))
- # BUILT-IN FUNCTIONS
- # print()
- # input()
- # len()
- # min()
- # max()
- # sum()
- # sorted()
- # reversed()
- # range()
- # open()
- # round() # has 2 cousins in math: math.ceil(), math.floor()
- # constructor/recasting functions
- # int()
- # float()
- # list()
- # dict()
- # str()
- # set()
- # help() # you can use help() and dir() in the exam!
- # dir()
- # STRINGS
- myString = "Just sit right back and you'll hear a tale."
- # SLICING strings and list
- # myString = myString[start, stop]
- # revString = myString[::-1]
- # STRING METHODS
- # for item in dir(str):
- # if not item.startswith("_"):
- # print ("{}()".format(item))
- # myString.format()
- # myString.strip(), myString.rstrip()
- # myString.split() # returns a list of smaller strings
- # " ".join(listOfStrings)
- # myString.replace(someStr, newStr) # to remove.. myString(someSub, "")
- # myString.count(subStr) # return int
- # myString.find(subStr) # returns int index
- # case methods: myString.upper(), myString.lower()
- # Boolean/is methods: myString.isupper(), myString.isdigit()
- # LIST METHODS
- # +
- # myList.append(item)
- # myList.insert(i, item)
- # myList.extend(anotherList)
- # # -
- # myList.pop() # by index
- # myList.remove() # by value
- #
- # myList.reverse()
- # myList.sort()
- # myList.count(item)
- # DICTIONARIES
- # myDictionary[key] # retrieve value for that key
- # myDictionary[key] = value # kinda takes the place of update()
- # for _key_ in someDictionary: # IN looks at the keys
- # # or for k, v in someDictionary.item():
- # if _key_ in thisDictionary:
- # myDictionary.keys()
- # myDictionary.values()
- # SETS
- # mySet.add()
- # mySet.remove() # by value
- # mySet.pop() # removes a random entry!
- # MATH MODULE
- # import math
- # math.e
- # math.pi
- # math.ceil()
- # math.floor()
- # math.sqrt()
- # math.pow() # **, not to be confused with math.exp()
- # math.factorial()
- # full vs partial import
- # from math import factorial #... factorial() not math.factorial()
- # # aliased import
- # import math as m #... m.factorial(), m.e
- # # OPENING FILES
- # good practice: Ch 12 Task 4, 7, 8
- # I'll include these webinars in our follow up
- # with open("filename.txt", "r") as f:
- # myContent = f.readlines() # returns a list of line by line strings
- # import csv
- # with open("mock_data.csv", "r") as f:
- # myReader = list(csv.reader(f))
- # print(myReader)
- # for line in myReader:
- # # print(line[2])
- # print("{} is at {}".format(line[3], line[4])) # then we can get at positions within the line
- # student questions
- # Lab 31.21
- import csv
- # Type your code here.
- filename = input().rstrip()
- wordList = []
- with open(filename, "r") as f:
- ufList = list(csv.reader(f)) # optional arg delimiter="\t"
- # print(ufList)
- for row in ufList:
- for word in row:
- if word not in wordList:
- print("{} {}".format(word, row.count(word))) # here's where I missed the right paren of print() smh
- wordList.append(word)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement