CSE115 Lecture Activity 8-9

docx

School

University at Buffalo *

*We aren’t endorsed by this school

Course

115

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

2

Uploaded by incognito101234

Report
1.) A list is a sequence of values and the whole thing is enclosed in brackets, one could compile a list of animals or individual transactions involving money within a certain amount of time. A dictionary has keys and values that are separated by a colon and the whole thing is enclosed in curly brackets, using the previous example of individual transactions, one could have the keys represent every month and the values would be every transaction in that month. In this example, the dictionary was used to organize the information in the list and make it easier to comprehend. 2.) To remove the first element: list = ["cat","dog","turtle"] y = list.pop(0) print(list) which results in: ['dog', 'turtle'] To remove the last element: list = ["cat","dog","turtle"] y = list.pop() print(list) which results in: ['cat', 'dog'] 3.) 3.22 is a float, “cat” is a string, True is a Boolean, 3 is an integer, [3,”test”,”turtles”] is a list, and {“name”: ”Dave”, ”number”: 333} is a dictionary. 4.) The loop would run four iterations because on the fourth run is when the code interacts with the value 55. 5.) numlist=[22,11,33,55,22,66,77,88,55,33] numlist.sort() print(numlist) which results in: [11, 22, 22, 33, 33, 55, 55, 66, 77, 88] Since the list was sorted, the loop now runs six iterations for it to interact with the value 55. 6.) def subTract(list_int,int): total = 0 for i in list_int: total = total + i ret_val = int-total return ret_val 7.) import csv def csv2txt('input','output') as file: ret_val=[] with open('input.csv','r') as file: reader = csv.reader(file) for row in reader return ret_val
with open('output.txt','w') as file: for item in ret_val: file.write(item+'\n') 8.) The code is considered a nested loop so the runtime would be O(n 2 ). 9.) def dateCode_key(dict): return dict['date_code'] list.sort(key=dateCode_key) 10.) SQL commands are SELECT * which is where you define what column(s) you would like to select and then you follow with FROM which describes from where you want to retrieve the data, sometimes you can add WHERE which is an extra constraint. Next is CREATE TABLE which is just a command to create tables and there is also INSERT ROW which allows one to insert a row in a table.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help