jugaadcode 0.1.15__tar.gz → 0.1.17__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/PKG-INFO +1 -1
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/pyproject.toml +1 -1
- jugaadcode-0.1.17/src/jugaadcode/anagram.py +86 -0
- jugaadcode-0.1.17/src/jugaadcode/trailing_zeros.py +64 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode.egg-info/PKG-INFO +1 -1
- jugaadcode-0.1.15/src/jugaadcode/anagram.py +0 -115
- jugaadcode-0.1.15/src/jugaadcode/trailing_zeros.py +0 -16
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/README.md +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/setup.cfg +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/__init__.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/armstrong.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/binary_search.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/bubble_sort.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/capitalize_words.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/character_frequency.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/climbing_stairs.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/coin_change.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/count_vowels.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/counting_sort.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/duplicate_number.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/even_odd.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/factorial.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/factorial_trailing_zeros_direct.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/factorial_with_trailing_zeros.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/fibonacci.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/find_max.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/find_min.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/first_non_repeating.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/gcd.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/harshad_number.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/input_utils.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/insertion_sort.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/kth_largest.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/lcm.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/linear_search.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/longest_consecutive.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/longest_word.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/matrix_transpose.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/maximum_subarray.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/merge_sort.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/move_zeros.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/pair_with_difference.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/palindrome.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/perfect_number.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/power.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/prime.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/quick_sort.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/remove_duplicates_array.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/remove_duplicates_string.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/reverse_linked_list.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/reverse_number.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/reverse_string.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/second_largest.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/selection_sort.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/strong_number.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/subsequence.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/sum_of_digits.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/two_sum.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/valid_parentheses.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode/word_count.py +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode.egg-info/SOURCES.txt +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode.egg-info/dependency_links.txt +0 -0
- {jugaadcode-0.1.15 → jugaadcode-0.1.17}/src/jugaadcode.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def is_anagram(*args):
|
|
5
|
+
"""Check whether two or more strings are anagrams.
|
|
6
|
+
|
|
7
|
+
Supports:
|
|
8
|
+
- Interactive input
|
|
9
|
+
- Two individual strings
|
|
10
|
+
- Multiple strings, compared in pairs
|
|
11
|
+
- Lists, tuples, sets, and other iterables
|
|
12
|
+
- Collections containing pairs of strings
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
- bool for one pair
|
|
16
|
+
- list of bools for multiple pairs
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def compare_pair(pair):
|
|
20
|
+
first, second = pair
|
|
21
|
+
|
|
22
|
+
if not isinstance(first, str) or not isinstance(second, str):
|
|
23
|
+
raise TypeError("Both values must be strings.")
|
|
24
|
+
|
|
25
|
+
return sorted(first.casefold().replace(" ", "")) == sorted(
|
|
26
|
+
second.casefold().replace(" ", "")
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
def process_collection(values):
|
|
30
|
+
values = list(values)
|
|
31
|
+
|
|
32
|
+
if len(values) == 2 and all(
|
|
33
|
+
isinstance(value, str) for value in values
|
|
34
|
+
):
|
|
35
|
+
return compare_pair(values)
|
|
36
|
+
|
|
37
|
+
if len(values) % 2 == 0 and all(
|
|
38
|
+
isinstance(value, str) for value in values
|
|
39
|
+
):
|
|
40
|
+
return [
|
|
41
|
+
compare_pair(values[i:i + 2])
|
|
42
|
+
for i in range(0, len(values), 2)
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
if all(
|
|
46
|
+
isinstance(pair, (list, tuple)) and len(pair) == 2
|
|
47
|
+
for pair in values
|
|
48
|
+
):
|
|
49
|
+
results = [compare_pair(pair) for pair in values]
|
|
50
|
+
return results
|
|
51
|
+
|
|
52
|
+
raise ValueError(
|
|
53
|
+
"Provide two strings, an even number of strings, "
|
|
54
|
+
"or a collection of string pairs."
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# No arguments: interactive mode
|
|
58
|
+
if not args:
|
|
59
|
+
first = input("Enter the first string: ")
|
|
60
|
+
second = input("Enter the second string: ")
|
|
61
|
+
return compare_pair((first, second))
|
|
62
|
+
|
|
63
|
+
# Multiple positional arguments
|
|
64
|
+
if len(args) > 1:
|
|
65
|
+
if len(args) == 2 and all(isinstance(arg, str) for arg in args):
|
|
66
|
+
return compare_pair(args)
|
|
67
|
+
|
|
68
|
+
return process_collection(args)
|
|
69
|
+
|
|
70
|
+
value = args[0]
|
|
71
|
+
|
|
72
|
+
# One string: prompt for the second string
|
|
73
|
+
if isinstance(value, str):
|
|
74
|
+
second = input("Enter the second string to compare: ")
|
|
75
|
+
return compare_pair((value, second))
|
|
76
|
+
|
|
77
|
+
# Reject non-iterable values
|
|
78
|
+
if isinstance(value, (bytes, bytearray)) or not isinstance(
|
|
79
|
+
value, Iterable
|
|
80
|
+
):
|
|
81
|
+
raise TypeError(
|
|
82
|
+
"Input must be a string or an iterable of strings/pairs."
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# Process lists, tuples, sets, generators, and other iterables
|
|
86
|
+
return process_collection(value)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def trailing_zeros(*args):
|
|
5
|
+
"""
|
|
6
|
+
Count trailing zeros in the factorial of non-negative integers.
|
|
7
|
+
|
|
8
|
+
Examples:
|
|
9
|
+
trailing_zeros(5) -> 1
|
|
10
|
+
trailing_zeros(10) -> 2
|
|
11
|
+
trailing_zeros([5, 10, 25]) -> [1, 2, 6]
|
|
12
|
+
trailing_zeros((5, 10, 25)) -> (1, 2, 6)
|
|
13
|
+
trailing_zeros(5, 10, 25) -> (1, 2, 6)
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def calculate(n):
|
|
17
|
+
if isinstance(n, bool) or not isinstance(n, int):
|
|
18
|
+
raise TypeError("Input must be an integer.")
|
|
19
|
+
|
|
20
|
+
if n < 0:
|
|
21
|
+
raise ValueError("Number must be non-negative.")
|
|
22
|
+
|
|
23
|
+
count = 0
|
|
24
|
+
|
|
25
|
+
while n > 0:
|
|
26
|
+
n //= 5
|
|
27
|
+
count += n
|
|
28
|
+
|
|
29
|
+
return count
|
|
30
|
+
|
|
31
|
+
# Interactive input
|
|
32
|
+
if not args:
|
|
33
|
+
n = int(input("Enter a non-negative integer: "))
|
|
34
|
+
return calculate(n)
|
|
35
|
+
|
|
36
|
+
# Multiple positional arguments
|
|
37
|
+
if len(args) > 1:
|
|
38
|
+
return tuple(calculate(n) for n in args)
|
|
39
|
+
|
|
40
|
+
value = args[0]
|
|
41
|
+
|
|
42
|
+
# Single integer
|
|
43
|
+
if isinstance(value, int) and not isinstance(value, bool):
|
|
44
|
+
return calculate(value)
|
|
45
|
+
|
|
46
|
+
# Reject strings and bytes
|
|
47
|
+
if isinstance(value, (str, bytes, bytearray)):
|
|
48
|
+
raise TypeError(
|
|
49
|
+
"Input must be an integer or an iterable of integers."
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# Lists, tuples, and other iterables
|
|
53
|
+
if isinstance(value, Iterable):
|
|
54
|
+
numbers = list(value)
|
|
55
|
+
results = [calculate(n) for n in numbers]
|
|
56
|
+
|
|
57
|
+
if isinstance(value, tuple):
|
|
58
|
+
return tuple(results)
|
|
59
|
+
|
|
60
|
+
return results
|
|
61
|
+
|
|
62
|
+
raise TypeError(
|
|
63
|
+
"Input must be an integer or an iterable of integers."
|
|
64
|
+
)
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
from collections import Counter
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def is_anagram(*args):
|
|
5
|
-
"""
|
|
6
|
-
Check whether two or more strings form anagrams.
|
|
7
|
-
|
|
8
|
-
Supports:
|
|
9
|
-
is_anagram("listen", "silent")
|
|
10
|
-
is_anagram(["listen", "silent"])
|
|
11
|
-
is_anagram(("listen", "silent"))
|
|
12
|
-
is_anagram(("listen", "silent"), ("hello", "world"))
|
|
13
|
-
is_anagram("listen", "silent", "hello", "world")
|
|
14
|
-
|
|
15
|
-
Spaces and letter case are ignored.
|
|
16
|
-
|
|
17
|
-
Parameters
|
|
18
|
-
----------
|
|
19
|
-
*args : str or collections of strings
|
|
20
|
-
Two strings for a single comparison, or multiple pairs
|
|
21
|
-
supplied as separate arguments or collections.
|
|
22
|
-
|
|
23
|
-
Returns
|
|
24
|
-
-------
|
|
25
|
-
bool or list[bool]
|
|
26
|
-
A boolean for one comparison, or a list of booleans
|
|
27
|
-
for multiple comparisons.
|
|
28
|
-
|
|
29
|
-
Raises
|
|
30
|
-
------
|
|
31
|
-
TypeError
|
|
32
|
-
If an input is not a string or a supported collection.
|
|
33
|
-
ValueError
|
|
34
|
-
If a comparison does not contain exactly two strings,
|
|
35
|
-
or either string is empty after removing whitespace.
|
|
36
|
-
"""
|
|
37
|
-
|
|
38
|
-
if not args:
|
|
39
|
-
first = input("Enter first string: ")
|
|
40
|
-
second = input("Enter second string: ")
|
|
41
|
-
args = (first, second)
|
|
42
|
-
|
|
43
|
-
def normalize(text):
|
|
44
|
-
if not isinstance(text, str):
|
|
45
|
-
raise TypeError("Every string must be of type str.")
|
|
46
|
-
|
|
47
|
-
normalized = "".join(text.split()).casefold()
|
|
48
|
-
|
|
49
|
-
if not normalized:
|
|
50
|
-
raise ValueError(
|
|
51
|
-
"Strings must contain at least one non-whitespace character."
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
return Counter(normalized)
|
|
55
|
-
|
|
56
|
-
def compare_pair(pair):
|
|
57
|
-
if len(pair) != 2:
|
|
58
|
-
raise ValueError(
|
|
59
|
-
"Each anagram comparison must contain exactly two strings."
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
first, second = pair
|
|
63
|
-
return normalize(first) == normalize(second)
|
|
64
|
-
|
|
65
|
-
# Two strings represent one comparison.
|
|
66
|
-
if len(args) == 2 and all(isinstance(arg, str) for arg in args):
|
|
67
|
-
return compare_pair(args)
|
|
68
|
-
|
|
69
|
-
# Multiple strings represent consecutive pairs.
|
|
70
|
-
if all(isinstance(arg, str) for arg in args):
|
|
71
|
-
if len(args) % 2 != 0:
|
|
72
|
-
raise ValueError(
|
|
73
|
-
"Multiple strings must be supplied in pairs."
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
return [
|
|
77
|
-
compare_pair(args[index:index + 2])
|
|
78
|
-
for index in range(0, len(args), 2)
|
|
79
|
-
]
|
|
80
|
-
|
|
81
|
-
# A single collection may contain a pair of strings
|
|
82
|
-
# or multiple pairs of strings.
|
|
83
|
-
if len(args) == 1:
|
|
84
|
-
collection = args[0]
|
|
85
|
-
|
|
86
|
-
if isinstance(collection, (list, tuple)):
|
|
87
|
-
if len(collection) == 2 and all(
|
|
88
|
-
isinstance(item, str) for item in collection
|
|
89
|
-
):
|
|
90
|
-
return compare_pair(collection)
|
|
91
|
-
|
|
92
|
-
results = []
|
|
93
|
-
|
|
94
|
-
for pair in collection:
|
|
95
|
-
if not isinstance(pair, (list, tuple)):
|
|
96
|
-
raise TypeError(
|
|
97
|
-
"Multiple comparisons must be supplied as pairs."
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
results.append(compare_pair(pair))
|
|
101
|
-
|
|
102
|
-
return results
|
|
103
|
-
|
|
104
|
-
# Multiple pairs passed as separate arguments.
|
|
105
|
-
results = []
|
|
106
|
-
|
|
107
|
-
for pair in args:
|
|
108
|
-
if not isinstance(pair, (list, tuple)):
|
|
109
|
-
raise TypeError(
|
|
110
|
-
"Supply strings in pairs or provide collections of string pairs."
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
results.append(compare_pair(pair))
|
|
114
|
-
|
|
115
|
-
return results
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
from collections.abc import Iterable
|
|
2
|
-
|
|
3
|
-
def trailing_zeros(*args):
|
|
4
|
-
if n is None:
|
|
5
|
-
n = int(input("Enter a number: "))
|
|
6
|
-
|
|
7
|
-
if n < 0:
|
|
8
|
-
raise ValueError("Number must be non-negative")
|
|
9
|
-
|
|
10
|
-
count = 0
|
|
11
|
-
|
|
12
|
-
while n > 0:
|
|
13
|
-
n //= 5
|
|
14
|
-
count += n
|
|
15
|
-
|
|
16
|
-
return count
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|