1. Which of the following statements create a dictionary?
a) d = {}
b) d = {“john”:40, “peter”:45}
c) d = {40:”john”, 45:”peter”}
d) All of the mentioned
2. Select the correct way to print Emma’s age.
student = {1: {'name': 'Emma', 'age': '27', 'sex': 'Female'},2: {'name': 'Mike', 'age': '22',
'sex': 'Male'}}
a) student[0][1]
b) student[1][“age”]
c) student[0][“age”]
3. Which of the following will delete key_value pair for key="tiger" in dictionary?
a) del dic["tiger"]
b) dic["tiger"].delete()
c) delete(dic.["tiger"])
d) del(dic.["tiger"])
4. Which of the following are true of Python dictionaries:
a) A dictionary can contain any object type except another dictionary.
b) All the keys in a dictionary must be of the same type.
c) Items are accessed by their position in a dictionary.
d) Dictionaries can be nested to any depth.
e) Dictionaries are mutable.
f) Dictionaries are accessed by key.
5. Write a function that creates a dictionary where the key is the number from 1 to n and
values have the message "Odd" or "Even" next to each number.
Example : If n=5 then the dictionary is
D={1:"Odd",2:"Even",3:"Odd"……}
6. Write a function that takes a dictionary student as parameter where the key is the name
of the students and the value is his percentage. This functions transfer the contents of
Dictionary Student to Dictionary Toppers if their percentage is above 90
7. Write a function that takes a string as the parameter and creates a dictionary that keeps
the track of the alphabets present in the string along with its count.
Example if the string is OCCURRENCE then the dictionary must be
{"O":1,"C":3,"U":1,"R":2,"E":2,"N":1}
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller Stevendurby. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $5.49. You're not tied to anything after your purchase.