Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Find the dictionary keys that are present in the list

I am new to python object oriented programming. I am trying to solve a problem where I have to define a class , create a method , write the code inside it and then create a object and call that method. I am a little confused on how to go forward with it.

Example : {1:’A’,2:’B}
L : [1,2,3,4]

Find the dictionary keys that are present in the list (without using for loop)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Another simple approach can be to use intersection():

my_dict = {1: 'A', 2: 'B'}
my_list = [1, 2, 3, 4]

output = set(my_dict).intersection(my_list)
print(output)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading