Created
June 8, 2018 20:28
-
-
Save chryss/5332163c89260242b0573c6824b49423 to your computer and use it in GitHub Desktop.
What to do when an API returns EITHER a scalar/string OR a list of scalars/strings, and you want the first one
This file contains 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
mylist = ['a', 'b'] | |
mynotalist = 'a' | |
def getthething(athing): | |
return list(athing)[0] | |
print(getthething(mylist)) | |
print(getthething(mynotalist)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment