INTRO TO CS (QUIZ #9)

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What is printed by the following statements? mydict = {"cat":12, "dog":6, "elephant":23} mydict["mouse"] = mydict["cat"] + mydict["dog"] print(mydict["mouse"])

18

What is printed by the following statements? mydict = {"cat":12, "dog":6, "elephant":23, "bear":20} answer = mydict.get("cat") // mydict.get("dog") print(answer)

2

What is printed by the following statements? total = 0 mydict = {"cat":12, "dog":6, "elephant":23, "bear":20} for akey in mydict: if len(akey) > 3: total = total + mydict[akey] print(total)

43

What is printed by the following statements? mydict = {"cat":12, "dog":6, "elephant":23} print(mydict["dog"])

6

What is printed by the following statements? mydict = {"cat":12, "dog":6, "elephant":23, "bear":20} yourdict = mydict yourdict["elephant"] = 999 print(mydict["elephant"])

999

dictionary

A collection of key-value pairs that maps from keys to values. The keys can be any immutable type, and the values can be any type.

key

A data item that is mapped to a value in a dictionary. Keys are used to look up values in a dictionary.

mapping type

A mapping type is a data type comprised of a collection of keys and associated values. Python's only built-in mapping type is the dictionary. Dictionaries implement the associative array abstract data type.

key-value pair

One of the pairs of items in a dictionary. Values are looked up in a dictionary by key.

What is printed by the following statements? mydict = {"cat":12, "dog":6, "elephant":23, "bear":20} keylist = list(mydict.keys()) keylist.sort() print(keylist[3])

elephant

What is printed by the following statements? mydict = {"cat":12, "dog":6, "elephant":23, "bear":20} print(23 in mydict)

false

T/F A dictionary is an unordered collection of key-value pairs

true

What is printed by the following statements? mydict = {"cat":12, "dog":6, "elephant":23, "bear":20} print("dog" in mydict)

true


Set pelajaran terkait

Postpartum & Newborn Discharge Teaching BREASTFEEDING 4th semester maternity nursing

View Set

CARBOHYDRATES, FATS, AND PROTEINS

View Set

Job 16 - Flashcard MC Questions - Ted Hildebrandt

View Set

Mental Health ATI Book ?s (exam 1)

View Set

hootsuite social marketing certification

View Set

Business Policy and Strat Exam 2 Questions

View Set