0

It seems that six library does not have a tuple type definition and I am currently looking to write the code below in a way that works with both Python 2 and Python 3.

return (type(key) in (types.TupleType, types.ListType)

PS. Don't blame me for that line, I only try to port it, is not written by me ;)

Nain
  • 1,204
  • 1
  • 12
  • 17
sorin
  • 161,544
  • 178
  • 535
  • 806

1 Answers1

4

The best way would be:

return isinstance(key, (tuple, list))

This is simple, direct, clear, works in both 2.x and 3.x, and properly handles subclasses.

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662