-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
26 lines (21 loc) · 889 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
commons_prefix="http://commons.wikimedia.org/wiki/Special:FilePath/"
def is_iterable(obj):
try:
iter(obj)
return True
except TypeError:
return False
def is_named_entiy(obj):
if isinstance(obj, str):
return any([char.isupper() for char in obj])
elif isinstance(obj, list) or isinstance(obj, set):
return any([is_named_entiy(item) for item in obj])
elif isinstance(obj, tuple) and len(obj) == 2 and isinstance(obj[0], str) and is_iterable(obj[1]):
return is_named_entiy(obj[0]) or is_named_entiy(obj[1])
if __name__ == '__main__':
print(is_named_entiy("Hello"))
print(is_named_entiy("hello"))
print(is_named_entiy(["Hello", "world"]))
print(is_named_entiy(["hello", "world"]))
print(is_named_entiy(("Hello", ["world", "earth"])))
print(is_named_entiy(("hello", ["world", "earth"])))