Question

Write statements to remove spaces from dictionary keys Write statements to get the key, value and...

Write statements to remove spaces from dictionary keys

Write statements to get the key, value and item in a dictionary

Write statements to replace dictionary values with their sum

python

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code for Question - 1:

Python program to remove space from keys:-

# Python program to remove space from keys
  
# creating a dictionary of type string
marks = {"M a h e s h":[50,40,50,35,45], "G o p i":[60,90,45,32,65], "P r e m":[90,94,36,69,50]};

#printing Current dictionary
print("Current dictionary is:", marks)
  
# removing spaces from keys
# storing them in sam dictionary
marks = {x.replace(' ', ''): v
for x, v in marks.items()}
  
# printing new dictionary
print ("New dictionary : ",marks)

Code Screenshot:

Output Screenshot:

Code for Question - 2:

Python program to get the key, value and item in a dictionary:-

#Python program to get the key, value and item in a dictionary

# creating a dictionary of type string
marks = {"Mahesh":[50,40,50,35,45], "Gopi":[60,90,45,32,65], "Prem":[90,94,36,69,50]};

#printing the keys of Dictionary
print("keys in Dictionary")
print(marks.keys())

#printing the values of Dictionary
print("values in Dictionary")
print(marks.values())

#printing the items of Dictionary
print("items in Dictionary")
print(marks.items())

Code Screenshot:

Output Screenshot:

Code for Question - 3:

Python program to replace dictionary values with their sum:-

#Python program to replace dictionary values with their sum

# creating a dictionary of type string
marks = {"Mahesh":[50,40,50,35,45], "Gopi":[60,90,45,32,65], "Prem":[90,94,36,69,50]};

#printing the Current dictionary
print("Current dictionary is: \n", marks)

#Loop for Replacing of sum Values in dictionary
for i in marks :
marks[i]=sum(marks[i]);

#printing the Upadted dictionary
print("Upadted dictionary with sum of Values:\n",marks)

Code Screenshot:

Output Screenshot:

Note: Dear sir, please consider my work and give up note.

Add a comment
Know the answer?
Add Answer to:
Write statements to remove spaces from dictionary keys Write statements to get the key, value and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • using python Write a function that takes a dictionary and a list of keys as 2...

    using python Write a function that takes a dictionary and a list of keys as 2 parameters. It removes the entries associated with the keys from the given dictionary Your function should not print or return anything. The given dictionary should be modified after the function is called Note: it means that you can't create another dictionary in your function. Since dictionaries are mutable, you can modify them directly def remove_keys (dict, key_list) "" "Remove the key, value pair from...

  • USING PYTHON! a) Programmatically (do not just write a definition!) create a dictionary whose keys are...

    USING PYTHON! a) Programmatically (do not just write a definition!) create a dictionary whose keys are the integers 1 through 10 and whose respective values are the keys cubed (e.g. a key of 5 has a value of 125). b) Write a function that, given a user inputted string, outputs a dictionary where each letter is a key and each value is the letter’s position in the string. Note that you ​must handle cases where a word could contain the...

  • Python 5. Write a function named grade_components that has one parameter, a dictionary. The keys for...

    Python 5. Write a function named grade_components that has one parameter, a dictionary. The keys for the dictionary are strings and the values are lists of numbers. The function should create a new dictionary where the keys are the same strings as the original dictionary and the values are tuples. The first entry in each tuple should be the weighted average of the non-negative values in the list (where the weight was the number in the 0 position of the...

  • in python Write a program that keeps a dictionary in which both keys and values are...

    in python Write a program that keeps a dictionary in which both keys and values are strings—names of students and their course grades. Prompt the user of the program to add or remove students, to modify grades, or to print all grades. The printout should be sorted by name and formatted like this: Carl: B- Joe: C Sarah: A Francine: A

  • 3 Dn Ent Write a python program to create a Dictionary named grade with the given...

    3 Dn Ent Write a python program to create a Dictionary named grade with the given items and do the below operations: i. 15 i. Create Dictionary with keys-{'Monday', 'Tuesday', 'Wednesday Thursday', 'Friday') ii. values-{1, 2, 3, 4, 5) ii. Now append another item with key-'Saturday') and value-(63 to the already created Dictionary and print it.

  • Your program has a dictionary called classes. The keys in classes are teacher's last names (as...

    Your program has a dictionary called classes. The keys in classes are teacher's last names (as strings), and the corresponding values are the number of students in that teacher's class. For example, if Mr. Brown has 17 students in her class, then 'Brown' might be a key in classes with a corresponding value of 17. Write a few lines in Python that will do the following: Ask the user to enter the last name of a teacher IF that last...

  • This script will create a dictionary whose keys are all the directories listed in thePATH system...

    This script will create a dictionary whose keys are all the directories listed in thePATH system variable, and whose values are the number of files in each of these directories. The script will also print each directory entry sorted by directory name. The script will use the following five functions to get the required results get_environment_variable_value() get_dirs_from_path() get_file_count() get_file_count_for_dir_list() print_sorted_dictionary() get_environment_variable_value() The header for this function must be This function must accept a shell variable as its only parameter The...

  • Which method would you use to get the value associated with a specific key and remove...

    Which method would you use to get the value associated with a specific key and remove that key-value pair from the dictionary? Group of answer choices popitem items pop list

  • python Which of the following statements are true? SELECT ALL THAT APPLY A dictionary is not...

    python Which of the following statements are true? SELECT ALL THAT APPLY A dictionary is not iterable. If die is a dictionary, dictionary returns a list of all the keys in the If my_dict is a dictionary, it can be sorted in ascending order of its keys using the dictionary's sort function. If my_dict is a dictionary, and k is a variable, the structure k in my_dict returns True if k is a key in the dictionary.

  • 5. Write a Python program to sort a dictionary by value in descending order (Note: you...

    5. Write a Python program to sort a dictionary by value in descending order (Note: you need to sort the entries, i.?., key-value pairs in the dictionary, not only the values in the dictionary).

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT