mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Add is_iterable utility function
This commit is contained in:
parent
e6eec79bca
commit
6cafa73441
2 changed files with 48 additions and 1 deletions
|
@ -15,6 +15,18 @@ def is_string(seq):
|
|||
return isinstance(seq, (text_type, binary_type))
|
||||
|
||||
|
||||
def is_iterable(seq, include_strings=False):
|
||||
"""Identify whether the input is an iterable."""
|
||||
if not include_strings and is_string(seq):
|
||||
return False
|
||||
|
||||
try:
|
||||
iter(seq)
|
||||
return True
|
||||
except TypeError:
|
||||
return False
|
||||
|
||||
|
||||
def is_sequence(seq, include_strings=False):
|
||||
"""Identify whether the input is a sequence.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue