Skip to content

Commit c8f90e1

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] clean code: variable naming
1 parent abf61d2 commit c8f90e1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/hackerrank/interview_preparation_kit/sorting/ctci_bubble_sort.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66

77
LOGGER = logging.getLogger(__name__)
8+
SEPARATOR = "\n"
89

910

1011
# pylint: disable=R0903:too-few-public-methods
@@ -46,9 +47,10 @@ def count_swaps(group: list[int]) -> str:
4647
sortable_group = SortableGroup(group)
4748
sortable_group.bubble_sort()
4849

49-
nl = "\n"
50-
output = f'Array is sorted in {sortable_group.count} swaps.{nl}' + \
51-
f'First Element: {sortable_group.group[0]}{nl}' + \
52-
f'Last Element: {sortable_group.group[len(sortable_group.group)-1]}{nl}'
50+
last = len(sortable_group.group) - 1
51+
52+
output = f'Array is sorted in {sortable_group.count} swaps.{SEPARATOR}' + \
53+
f'First Element: {sortable_group.group[0]}{SEPARATOR}' + \
54+
f'Last Element: {sortable_group.group[last]}{SEPARATOR}'
5355

5456
return output

0 commit comments

Comments
 (0)