Created
April 4, 2016 13:27
-
-
Save lsloan/6ea601dd7fe6b2d2337f60ca7dd4e32c to your computer and use it in GitHub Desktop.
Attempting to find a common differentiation between strings and other iterable collections.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment