I think it might be preferred to actually do
if isinstance(x, str):
do_something_with_a_string(x)
elif isinstance(x, dict):
do_somethting_with_a_dict(x)
else:
raise ValueError
2 Alternate forms, depending on your code one or the other is probably considered better than that even. One is to not look before you leap
try:
one, two = tupleOrValue
except TypeError:
one = tupleOrValue
two = None
The other approach is from Guido and is a form of function overloading which leaves your code more open ended.