Q:

Get all values from the dictionary and add them to a list but don’t add duplicates using python programming

belongs to collection: Python Data Structure Exercises

0

Get all values from the dictionary and add them to a list but don’t add duplicates

Given:

speed = {'jan': 47, 'feb': 52, 'march': 47, 'April': 44, 'May': 52, 'June': 53, 'july': 54, 'Aug': 44, 'Sept': 54}

Expected Outcome:

[47, 52, 44, 53, 54]

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution:

speed = {'jan': 47, 'feb': 52, 'march': 47, 'April': 44, 'May': 52, 'June': 53,
         'july': 54, 'Aug': 44, 'Sept': 54}

print("Dictionary's values - ", speed.values())

speed_list = list()

# iterate dict values
for val in speed.values():
    # check if value not present in a list
    if val not in speed_list:
        speed_list.append(val)
print("unique list", speed_list)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Remove duplicates from a list and create a tuple a... >>
<< Iterate a given list and check if a given element ...