Sitemap
Pramila Madhava & Jibrael Jos, PhD

Pramila Madhava & Jibrael Jos, PhD

As an educationist with a passion for technology and a love for problem-solving,we aim to inspire students to embrace innovation and challenges with confidence.

Logic Building-Basic Level-Dictionary

2 min readApr 12, 2025

Python Coding Questions

1. Write a program that reads the string and stores it as a key in a dictionary, counting the occurrence of each character excluding spaces. data=”Corpus Juris Secundum”

Press enter or click to view image in full size

Output

The occurrence of Characters in the String is:

{‘c’: 2, ‘o’: 1, ‘r’: 2, ‘p’: 1, ‘u’: 4, ‘s’: 3, ‘j’: 1, ‘i’: 1, ‘e’: 1, ’n’: 1, ‘d’: 1, ‘m’: 1}

2. Write a program that reads through each word in the list and finds the occurrence of each word in the list data=[‘Arise’, ‘But’, ‘It’, ‘Juliet’, ‘But’, ‘already’,’and’, ‘breaks’, ‘east’, ‘It’]

Output:

The occurrence of each word in the list is :

{‘Arise’: 1, ‘But’: 2, ‘It’: 2, ‘Juliet’: 1, ‘already’: 1, ‘and’: 1, ‘breaks’: 1, ‘east’: 1}

3. Write a program to extract the name as the key and domain as the value to a dictionary data=”sam@gmail.com bob@gmail.com luci@rediff.com”

Output:

The name and domain names are :

{‘sam’: ‘gmail.com’, ‘bob’: ‘gmail.com’, ‘luci’: ‘rediff.com’}

Get Pramila Madhava & Jibrael Jos, PhD’s stories in your inbox

Join Medium for free to get updates from this writer.

4. Write a program to store the cube of numbers as a key-value pair in a dictionary. The dictionary should not hold any value which are multiples of 3.

Output:

Enter the number: 7

Cube of numbers are :

{1: 1, 2: 8, 4: 64, 5: 125, 7: 343}

5. Write a program to generate the username and password for users and store it as a list of values in a dictionary against the name of the user based on the data collected from the user. Enter the firstname, mobnumber, DOB. Here username is a combination of firstname+DOB , password is a combination of mobnumber+DOB.

Output:

Enter the number of users 2

Enter the user 1 firstname Ronald

Enter the user 1 last 4 digits of mobile number 3443

Enter the user 1 year of birth 2003

Enter the user 2 firstname Adil

Enter the user 2 last 4 digits of mobile number 4556

Enter the user 2 year of birth 2004

The Generated username and password for the users are:

{‘Ronald’: [‘Ronald2003’, ‘34432003’], ‘Adil’: [‘Adil2004’, ‘45562004’]}

--

--

Pramila Madhava & Jibrael Jos, PhD
Pramila Madhava & Jibrael Jos, PhD

Written by Pramila Madhava & Jibrael Jos, PhD

As an educationist with a passion for technology and a love for problem-solving,we aim to inspire students to embrace innovation and challenges with confidence.