Skip to content

Instantly share code, notes, and snippets.

@rikwatson
Created April 1, 2019 12:46
Show Gist options
  • Save rikwatson/794e8d8a7101654ec1e321631ccd06f3 to your computer and use it in GitHub Desktop.
Save rikwatson/794e8d8a7101654ec1e321631ccd06f3 to your computer and use it in GitHub Desktop.
How to flatten a tuple in Python
# Basically the problem was that I wanted to create a flat tuple from a tuple and a single value like such:
#
val = 3
tup = ( 'a', 3.14, "zzz" )
# I wanted this:
#
# ( 3, 'a', 3.14, "zzz" )
#
# not this:
#
# ( 3, ( 'a', 3.14, "zzz" ) )
print (val,) + tup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment