mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
0c7c5fa7b0
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/asottile/pyupgrade: v3.0.0 → v3.1.0](https://github.com/asottile/pyupgrade/compare/v3.0.0...v3.1.0) - [github.com/codespell-project/codespell: v2.2.1 → v2.2.2](https://github.com/codespell-project/codespell/compare/v2.2.1...v2.2.2) * updating DIRECTORY.md * Fix typo discovered by codespell * Fix typo discovered by codespell * Update .pre-commit-config.yaml * Update .pre-commit-config.yaml * Update .pre-commit-config.yaml Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
40 lines
949 B
Python
40 lines
949 B
Python
"""
|
|
References: wikipedia:square free number
|
|
python/black : True
|
|
flake8 : 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()
|