Question

write a program in python for following x = { 'a' : 1 , 'b':2 ,...

write a program in python for following

x = { 'a' : 1 , 'b':2 , 'c':3, 'd':4 }

For the following key,value pairs of dictionary display those which are even values i.e for which the value is even.

i am trying like this but getting confused.

(k:v for k,v in x.items() if v%2 != 0

Homework Answers

Answer #1

#Python Code:-

def main():
  
# Given dictionary
x = { 'a' : 1 , 'b':2 , 'c':3, 'd':4 }
  
dict1={}
  
# Traversing dictionary to find out the even values and then add to new dictionary called dict1
for key,value in x.items():
if value%2==0:
dict1[key]=value
  
# Printing elements of dictionary having even value.
print("The items having even value in dictionary: ")
print(dict1)

if __name__=="__main__":
main()
  
  
  

Know the answer?
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
Similar Questions
Write a program in python reverse each and every word of the sentence using function taking...
Write a program in python reverse each and every word of the sentence using function taking string as input parameter from user and passing that string into function and also explain the logic ======================================= input: 'Exam is gonna be good' output: 'maxE si annog eb doog' ================ i am trying like this but getting confused '.'join([w::-1] for w in s.split()]) i need more focus on explanations because it is making me confuse i am not clear with concepts so please...
Write a Python program to create a dictionary from two lists without losing duplicate values. If...
Write a Python program to create a dictionary from two lists without losing duplicate values. If there is more values in the key list, then provided key should return an empty set if there is no match. (Hint: use defaultdict) Example: class_list = ['Class-V', 'Class-VI', 'Class-VII', 'Class-VIII','Class-IX'] id_list = [1, 2, 2, 3] Output: assuming you store the values in a data structure named temp print(temp["Class-V"]) # {1} print(temp["Class-IX"]) # set() can you please try and do on google colab
Which of the following strings P is a Python program. (b) P = “def f(x): x...
Which of the following strings P is a Python program. (b) P = “def f(x): x = 'am I a Python program?'” (d) P = “def f(x,y,z): return y” (e) P = “def f(x): return y” For each of the following Python programs P and input strings I, give the output P(I), (f) P = “def f(x): return str(len(x+x+'x'))”, I = “GAGAT” (g) P = “def f(x): return str(len(x))”, I=P (h) P = “def f(x): return str(1/int(x))”, I = “0”
Hello, I am trying to write a program in python that will determine if a sentence...
Hello, I am trying to write a program in python that will determine if a sentence has every letter in the alphabet, regardless if it is upper or lower case. The program needs to indicate if all letters are present or not, and print out the missing letters if there are any. Thanks for any help in advance.
Write a PYTHON program for the following: A dictionary courses lists summer school classes a student...
Write a PYTHON program for the following: A dictionary courses lists summer school classes a student is taking, along with information about the classes. For example, courses = { "CS 101" : { "full_name" : "Intro to CS with Python", "instructors" : [ "Sally", "Johnson" ], "tas" : ["Bob", "Joe",..., "Elroy"], "num_homeworks" : 6, "num_exams" : 2 }, "SPAN-SAA" : { "name" : "Beginning Spanish I", ... }, ... } Write a loop that computes the total number of homeworks...
(Python 3) If I have a list of keys and 3 lists of values, how can...
(Python 3) If I have a list of keys and 3 lists of values, how can I append these values into an existing key, value pair in a dictionary? Say I have: mykeys = ["John", "Sarah", "Lexi, "Cass"] values1 = [3, 5, 2, 6] values2 = [17, 18, 12, 21] values3 = [4, 7, 3, 0] How can I make it so my dictionary contains all three values in each of the keys. i.e.: {"John" : [3, 17, 4], "Sarah":...
this is in python 3.6 Write a program that prints to three significant figures the values...
this is in python 3.6 Write a program that prints to three significant figures the values of x and g(x) from x = 0 to x = 10 in increments of 2 units. The values of x include 0 and 10. The function g(x) is defined below: g(x): sqrt(x); x<4    sqrt(4); 4<=x The output of the first and last values are below: 0.000 0.000 ... ... 10.000 2.000
Working with Python! I am trying to use matplotlib on the jupyter notebook to graph a...
Working with Python! I am trying to use matplotlib on the jupyter notebook to graph a smooth curve scatter plot from data points in a dictionary like this, for example, and the positions of x and y are (x,y) sampleData = {"sample 1": ('3','5'), "sample 2": ('2','1'), "sample 3": ('2','2'), "sample 4":('6','7')}
(Python Programming) Write a program that prompts a user for a positive integer and then uses...
(Python Programming) Write a program that prompts a user for a positive integer and then uses a loop to calculate and display the sum of specific fractions as follows: Let's say the user enters 5, then your program will compute: 1/5 + 2/4 + 3/3 + 4/2 + 5/1 which is 8.7.
Hello! I am confused on the code for this question. Write a complete Python function called...
Hello! I am confused on the code for this question. Write a complete Python function called Frog, with two integer parameters M and N, where N has the default value of 5. The function computes and returns one of two results: if N is odd it returns the equation 2 * M + N, but if it is even it returns the equation 3 * M - N instead.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • Suppose that people's heights (in centimeters) are normally distributed, with a mean of 170 and a...
    asked 1 minute ago
  • Use the information from the following Income Statement to create and Projected Income Statement and solve...
    asked 14 minutes ago
  • An unequal tangent vertical curve has the following elements: g1=-3.25%, g2=75%, total length = 500.00’, length...
    asked 16 minutes ago
  • Please write clear definitions of the following legal terms. Commerce Clause Supremacy Clause Indictment Tort
    asked 20 minutes ago
  • Do you think Moralistic Therapeutic Deism is an accurate reflection of society today? What are relevant...
    asked 25 minutes ago
  • The mean operating cost of a 737 airplane is $2,071 per day. Suppose you take a...
    asked 34 minutes ago
  • Arguments can be made on both sides of this debate about the ethical implications of using...
    asked 40 minutes ago
  • In the Chapter, they mention the idea of strategizing around your cash flows. Why are cash...
    asked 45 minutes ago
  • Company A signed a fixed-price $6,500,000 contract to construct a building. At the end of Year...
    asked 46 minutes ago
  • An unequal tangent vertical curve has the following elements: g1=-3.25%, g2=1.75%, total length = 500.00’, length...
    asked 52 minutes ago
  • In a previous​ year, 61​% of females aged 15 and older lived alone. A sociologist tests...
    asked 1 hour ago
  • Topic: Construction - Subsurface Investigation (Note: Briefly discuss in your own words, 1 paragraph minimum.) Typically...
    asked 1 hour ago