forked from TheAlgorithms/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
is_square_free.py
39 lines (32 loc) · 944 Bytes
/
is_square_free.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
References: wikipedia:square free number
psf/black : True
ruff : True
"""
from __future__ import annotations
def is_square_free(factors: list[int]) -> bool:
"""
# doctest: +NORMALIZE_WHITESPACE
This functions takes a list of prime factors as input.
returns True if the factors are square free.
>>> is_square_free([1, 1, 2, 3, 4])
False
These are wrong but should return some value
it simply checks for repetition in the numbers.
>>> is_square_free([1, 3, 4, 'sd', 0.0])
True
>>> is_square_free([1, 0.5, 2, 0.0])
True
>>> is_square_free([1, 2, 2, 5])
False
>>> is_square_free('asd')
True
>>> is_square_free(24)
Traceback (most recent call last):
...
TypeError: 'int' object is not iterable
"""
return len(set(factors)) == len(factors)
if __name__ == "__main__":
import doctest
doctest.testmod()