w3resource

Python Exercise: Find maximum and the minimum value in a set

Python sets: Exercise-14 with Solution

Write a Python program to find maximum and the minimum value in a set.

Sample Solution:-

Python Code:

#Create a set
seta = set([5, 10, 3, 15, 2, 20])
#Find maximum value
print(max(seta))
#Find minimum value
print(min(seta))

Sample Output:

20                                                                                                            
2 

Pictorial Presentation:

NumPy Sets: Find maximum and the minimum value in a set.

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to use of frozensets.
Next: Write a Python program to find the length of a set.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Returns True if there are duplicate values in a flat list, False otherwise

Example:

def tips_duplicates(lst):
  return len(lst) != len(set(lst))

x = [2, 4, 6, 8, 4, 2]
y = [1, 3, 5, 7, 9]
print(tips_duplicates(x))
print(tips_duplicates(y))

Output:

True
False