Skip to content

Instantly share code, notes, and snippets.

@lsloan
Created April 4, 2016 13:27
Show Gist options
  • Save lsloan/6ea601dd7fe6b2d2337f60ca7dd4e32c to your computer and use it in GitHub Desktop.
Save lsloan/6ea601dd7fe6b2d2337f60ca7dd4e32c to your computer and use it in GitHub Desktop.
Attempting to find a common differentiation between strings and other iterable collections.
# Attempting to find a common differentiation
# between strings and other iterable collections.
import collections
testSubjects = [
'asdf',
1,
[1, ],
(1,),
set((1,)),
{'a': 1, }
]
testClasses = [cls for name, cls in collections.__dict__.items() if isinstance(cls, type)]
testClasses += [basestring]
for testClass in testClasses:
results = []
for testSubject in testSubjects:
result = isinstance(testSubject, testClass)
results.append(result)
if (
(results[1:] != results[:-1]) # All results are the same
):
for index, result in enumerate(results):
print testClass.__name__, testSubjects[index], result
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment