Skip to content

Instantly share code, notes, and snippets.

@chryss
Created June 8, 2018 20:28
Show Gist options
  • Save chryss/5332163c89260242b0573c6824b49423 to your computer and use it in GitHub Desktop.
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
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