mirror of
https://github.com/donnemartin/data-science-ipython-notebooks.git
synced 2024-03-22 13:30:56 +08:00
Tweaked docstrings.
This commit is contained in:
parent
0510eb997c
commit
595ab2358b
11
core/util.py
11
core/util.py
|
@ -2,6 +2,12 @@ class Util:
|
|||
|
||||
@classmethod
|
||||
def is_iterable(self, obj):
|
||||
"""Determines if obj is iterable.
|
||||
|
||||
Useful when writing functions that can accept multiple types of
|
||||
input (list, tuple, ndarray, iterator). Pairs well with
|
||||
convert_to_list.
|
||||
"""
|
||||
try:
|
||||
iter(obj)
|
||||
return True
|
||||
|
@ -10,9 +16,8 @@ class Util:
|
|||
|
||||
@classmethod
|
||||
def convert_to_list(self, obj):
|
||||
"""Useful when writing functions that can accept multiple types of
|
||||
input (list, tuple, ndarray, iterator). Checks if the object is a list.
|
||||
If it is not a list, converts it to a list.
|
||||
"""Converts obj to a list if it is not a list and it is iterable, else
|
||||
returns the original obj.
|
||||
"""
|
||||
if not isinstance(obj, list) and self.is_iterable(obj):
|
||||
obj = list(obj)
|
||||
|
|
Loading…
Reference in New Issue
Block a user