logo codesdope
Level 1
1.
Ask user to give name and marks of 10 different students. Store them in dictionary.

2.
Sort the dictionary created in previous example according to marks.
Hint
This type of example is given in tutorial

3.
Use dictionary to store antonyms of words. E.g.- 'Right':'Left', 'Up':'Down', etc. Display all words and then ask user to enter a word and display antonym of it.

4.
Count the number of occurrence of each letter in word "MISSISSIPPI". Store count of every letter with the letter in a dictionary.

5.
From the previous question, sort according to the number of letters.

6.
Take a list containg only strings. Now, take a string input from user and rearrange the elements of the list according to the number of occurence of the string taken from user in the elements of the list.
E.g.-LIST : ["no bun","bug bun bug bun bug bug","bunny bug","buggy bug bug buggy"]
STRING TAKEN : "bug"
OUTPUT LIST:["bug bun bug bun bug bug","buggy bug bug buggy","bunny bug","no bun"]
Answer
a = ["no bun","bug bun bug bun bug bug","bunny bug","buggy bug bug buggy"]
b = "bug"
c = {}
for i in a:
  count = 0
  for j in i.split():
    if j == b:
      count = count+1
  c[count]=i
d = []
for s in sorted(c):
  d.append(c[s])
d.reverse()
print d

									
Doubt? Ask question
Close

Welcome.please sign up.

Close

Welcome.please login.