Skip to content

Commit 17f8665

Browse files
committed
update documentation
1 parent 3e3db78 commit 17f8665

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

Python/chapter01/1.1 - Is Unique/miguel_1.1_sol.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,39 @@
77
I assume that the user will input a non-empty string
88
If the string is empty, then raise a ValueError exception
99
If the input is NOT a string, then raise a TypeError exception
10-
11-
Given: Expect:
12-
tacos true
13-
swag true
14-
bobby false
15-
california false
16-
orbit true
17-
e true
1810
"""
1911
import unittest
2012

2113

2214
def check_is_unique_input(input_str):
15+
"""
16+
Does some input checking for the is_unique function and its variants
17+
Raises exceptions if input_str is empty or if input_str is not of type string
18+
:param input_str: a string that we are checking to make
19+
:return:
20+
"""
2321
if not isinstance(input_str, str):
2422
raise TypeError("expected string as input")
2523
if input_str == "":
2624
raise ValueError("empty input string")
2725

2826

2927
def is_unique(input_str):
28+
"""
29+
Determines if input_str has all unique characters.
30+
input string MUST have at least 1 character. n>=1, where n is the number of characters in a string.
31+
Hence, the domain is now defined. Any input not within the domain will not be considered. (n < 1)
32+
An exception will be raised to handle faulty input.
33+
Given: Expect:
34+
tacos True
35+
swag True
36+
bobby False
37+
california False
38+
orbit True
39+
e true
40+
:param input_str: the string we want to check characters of
41+
:return: returns True if input_str has all unique characters, False otherwise
42+
"""
3043
check_is_unique_input(input_str)
3144
chars_seen = set()
3245
for c in input_str:
@@ -37,6 +50,18 @@ def is_unique(input_str):
3750

3851

3952
def is_unique_no_additional_data_structures(input_str):
53+
"""
54+
Variant of is_unique. Uses no additional data structures (besides the variables from the iterator)
55+
Given: Expect:
56+
tacos True
57+
swag True
58+
bobby False
59+
california False
60+
orbit True
61+
e True
62+
:param input_str: the string we want to check characters of
63+
:return: returns True if input_str has all unique characters, False otherwise
64+
"""
4065
check_is_unique_input(input_str)
4166
for i, c in enumerate(input_str):
4267
if c in input_str[i+1:]:

0 commit comments

Comments
 (0)