Dictionaries
Lists and Sort
Functions and Syntax
Syntax
Random1
Random2
100

Consider the following dictionary:

dict = { 'aardvark' : 'anthony', 'buffalo' : 'boris', 'zebra' : 'zelda' }

What would be the out of the following:

dict['aardvark']

'anthony'

100

What is the out of the following?

>>>a[100, 30, 20]
>>>a

100, 30, 20

100

In the following code, var1 is a(n)

def myFunction(var1)

var1 is a parameter

100

What is wrong with the following function?

def addOne(number): print number + 1

Everything is one line / there is no block indentation.

100

What would be the output of the following?

False

100

Can len() be used with tuples?  If so, why would you use it?

Yes, it would tell you the number of items in a tuple.

200

True or False:

each key in a dictionary must be unique

True

200

What is the output of the following?

>>>a[100, 30, 20]
>>>a[2]

20

200

What is the maximum number of tasks a good function should generally complete for you?

1 task

200

What word would you use to describe the following?

question = ('apple', 'banana', 'cherry')

This is a tuple

200

What programming paradigm describes this method of showing an image?

pic.show()

object oriented

200

If you were using a sequential search for “date”, how many items in the following list would your code need to look at?

[“banana”, “date”, “cherry”, “apple”]

2

300

True or False:

—Each key must be of a mutable type.

False, each key in a dictionary must be an immutable type.

300

Describe the code needed to set a list variable a that would store the values 100 and 20

>>> a[100, 20]

300

What is wrong with the following function, and why?

def countDown():
    while a > 1:
        print a
        a = a – 1

Variable a is never defined - we need to Prime the Pump.

300

Which operator would be completed last in the following expression?

a * b / d + e / f

+

300

What is the name for an immutable ordered collection of characters?

a string

300

White on the board the line of code that would give us access to a library of tools that would allow us to read data from a website.

import urllib

400

Given the following dictionary, could you change Boris' first name to Bob?  If so, how would you do this?

question = { "Aardvark" : "Anthony" ,  "Buffalo" : "Boris"}

Yes!

question[“Buffalo”] = “Bob”

400

Suppose you are using a binary search for the following list:

['bunny', 'cat', 'dog' ,'mouse']

What would be the first item you look at during your search?

dog

400

When using the style of software development that used for part 1 of project 4, what is the first function you should write for a program that will check the current weather in Boston?

A test function ex: test_checkWeather()

400

Write in one single line, a statement that would define a = 1, b = 2, and c = 3

a, b, c = 1, 2, 3

400

Could anything be done to make this line of code more efficient?  If so, write it on the explain what you would change to make this as simple as possible:

if (a > b) == True  and (b > a) == False:

if a > b:

400

Suppose I wanted to print “[fruit_name] is delicious!” for each fruit in the following list:

[“banana”, “date”, “cherry”, “apple”]

Which operation would be most appropriate: apply, filter, map, or reduce?

For double points, explain all three other operations!

map

500

Consider the following dictionary:

dict = { 'aardvark' : 'anthony', 'buffalo' : 'boris', 'zebra' : 'zelda' }

What would be the output of:

dict.keys()

['aardvark', 'buffalo', 'zebra']

500

What would be returned from the following statements?

number_list = range(-5, 5)

less_than_zero = list(filter(lambda x: x < 0, number_list))

print(less_than_zero)

[-5, -4, -3, -2, -1]

500

What would question(100) return given the following function??

def question(x):
  if x == 5:
    return 5
  else:
    return question(x - 5)

5

500

Write on the board a dictionary represented by the variable name dict, which contains two people:

Anthony Aardvark and Boris Buffalo

All or nothing, your syntax must be perfect.

{ "Aardvark" : "Anthony" ,  "Buffalo" : "Boris"}

500

Write the first line of an example of indefinite iteration, and explain how this is different from definite iteration.

While i > 1 :

This is different from definite iteration, which might be something like

for i in range (0,10):

500

If you were to sort the following list using the bubble sort method, what would your list look like after the first pass of sorting?

[“banana”, “date”, “cherry”, “apple”]

[“banana”, “cherry”, “apple”, “date”]