Last active
September 26, 2015 23:19
-
-
Save neoneo40/50ab42abb799a55c26c6 to your computer and use it in GitHub Desktop.
python sort, reverse in list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sort(digits, reverse=False): | |
digits.sort() | |
if reverse: | |
digits.reverse() | |
return digits | |
l = [5, 3, 1, 4, 9, 6] | |
print(sort(l)) | |
# [1, 3, 4, 5, 6, 9] | |
def sort(digits, reverse=False): | |
# digits.sort() | |
if reverse: | |
digits.reverse() # reverse()는 단순히 들어온 list를 반대로 보여주는 역할 | |
# digits[::-1] 과 똑같다. | |
return digits | |
l = [5, 3, 1, 4, 9, 6] | |
print(sort(l)) | |
# [5, 3, 1, 4, 9, 6] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment