Skip to content

Commit 9b04f46

Browse files
author
Oliver Ignetik
committed
Fix first_unique_chars
1 parent 560a739 commit 9b04f46

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Arrays/first_unique_char.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
def first_unique_chars(myStr):
1+
from typing import Tuple
2+
3+
def first_unique_chars(myStr: str) -> Tuple[int, str]:
24
chars = {}
35
for i, x in enumerate(myStr):
46
if x not in chars:
57
chars[x] = i
68
else:
79
chars[x] = -1
810

9-
for x in myStr:
10-
if x != -1:
11-
return chars[x]
11+
for char in chars:
12+
if chars[char] != -1:
13+
return (chars[char], char)
1214

13-
return -1
15+
raise ValueError("There are no unique chars")
1416

1517

16-
myStr = 'helleo'
18+
myStr = 'hhelleoo'
1719
print(first_unique_chars(myStr))

0 commit comments

Comments
 (0)