Skip to content

Commit 4b67591

Browse files
committed
Fix empty input edge case and correct output formatting
1 parent 68473af commit 4b67591

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

sorts/pigeonhole_sort.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ def pigeonhole_sort(a):
1111
>>> a == b
1212
True
1313
"""
14+
if not a :
15+
return # this handles empty list
1416
# size of range of values in the list (ie, number of pigeonholes we need)
1517

1618
min_val = min(a) # min() finds the minimum value
@@ -38,7 +40,7 @@ def pigeonhole_sort(a):
3840
def main():
3941
a = [8, 3, 2, 7, 4, 6, 8]
4042
pigeonhole_sort(a)
41-
print("Sorted order is:", " ".join(a))
43+
print("Sorted order is:", " ".join(map(str,a))) # it converts integer into string
4244

4345

4446
if __name__ == "__main__":

0 commit comments

Comments
 (0)