Python dict and list methods

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

"extend(iterable)"

"How do you add an iterable to a list"

"append(item)"

"How do you add items to a list?"

"count(x)"

"How do you determine the number of times an items occurs in a list?"

"index(i)"

"How do you find the location of a particular item in a list"

"insert(index,item)"

"How do you insert an item at a particular location"

"copy()"

"How do you return a shallow copy of a dict?"

"popitem()"

"How would get the first item from the top of the dictionary (which would be random)"

"has_key(key)"

"How would you check for the existence of a key only?"

"dict1.update(dict2) will merge all of dict2's entries into dict1"

"How would you combine two dictionaries?"

"fromkeys(sequence_containing_keys,[value])"

"How would you create a new dictionary subset from a dictionary?"

,"iteritems(), iterkeys(), itervalues()"

"How would you create an iterator for items keys, and values respectively?"

"setdefault"

"How would you do the same thing for setting a dictionary value?"

"pop(key, default)"

"How would you retrieve and remove a particular key"

,"get(key) will return None or get(key, default) will return the default value"

"How would you search for a key value but not return an exception if it is not found?"

"clear()"

How do you remove all items from a dict?

the values method returns all values as a list, or an iterable in 3

How do you retrieve the values for a dictionary

.pop(x, i). Use with append() to create stacks.

How would you delete and return a particular item?

.remove(x) Raises an exception if not found. Same as <em>del</em>

How would you remove the first occurrence of x from a list?

items will return a list containing tuples of each key/value pair

How would you return all key values pairs without using an iterator?

.keys returns the keys of a dictionary as a list

What method returns all keys in a dictionary and in what format?


Set pelajaran terkait

Chapter 14: Capital Budgeting Decisions

View Set

ATI Nursing Care of Children Practice A, RN Nursing Care of Children Practice 2019 A ATI

View Set

PSY-5 (Ch.14 Altruism and Cooperation)

View Set

Policy Provisons, Riders and Options

View Set

Surgical Technology Ch 2 Take Home Quiz

View Set