mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-06 10:14:17 +08:00
Modernize Python 2 code to get ready for Python 3
This commit is contained in:
@ -59,14 +59,11 @@ def counting_sort(collection):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
# For python 2.x and 3.x compatibility: 3.x has not raw_input builtin
|
||||
# otherwise 2.x's input builtin function is too "smart"
|
||||
if sys.version_info.major < 3:
|
||||
input_function = raw_input
|
||||
else:
|
||||
input_function = input
|
||||
try:
|
||||
raw_input # Python 2
|
||||
except NameError:
|
||||
raw_input = input # Python 3
|
||||
|
||||
user_input = input_function('Enter numbers separated by a comma:\n')
|
||||
user_input = raw_input('Enter numbers separated by a comma:\n').strip()
|
||||
unsorted = [int(item) for item in user_input.split(',')]
|
||||
print(counting_sort(unsorted))
|
||||
|
Reference in New Issue
Block a user