0% found this document useful (0 votes)
6 views1 page

Python Dictionary Programming Guide

The document outlines an experiment for a Python programming lab focused on creating a dictionary. It includes two coding tasks: one for counting characters in a string and another for combining two lists into a dictionary. Sample code and expected outputs for both tasks are provided.

Uploaded by

Mailu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Python Dictionary Programming Guide

The document outlines an experiment for a Python programming lab focused on creating a dictionary. It includes two coding tasks: one for counting characters in a string and another for combining two lists into a dictionary. Sample code and expected outputs for both tasks are provided.

Uploaded by

Mailu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Sheet No: ……………

VNRVJIET
Name of the Experiment: Dictionary
Name of the Laboratory:
Python Programming and Practice Experiment No.: 5 Date:

a) Write a program to count the numbers of characters in the string and store them in a
dictionary data structure.

Code:

def count_characters(s):
char_count = {}
for char in s:
if char in char_count:
char_count[char] += 1
else:
char_count[char] = 1
return char_count

string1 = "good morning"


char_num = count_characters(string1)
print("Character Count:", char_num)

Output:

b) Write a program combine lists into a dictionary.

Code:
def combine_lists(keys, values):
return dict(zip(keys, values))

keys = ['name', 'age', 'city']


values = ['Kate', 23, 'New York']
combined_dict = combine_lists(keys, values)
print("Combined Dictionary:", combined_dict)

Output:

You might also like