Skip to main content

Checks if a variable is iterable

Project description

Determines if an object is iterable

This function uses a couple of different methods to find out if a variable is iterable

$pip install isiter
from isiter import isiter

from collections import namedtuple
fields_cor = "qt rgb r g b"
classname_cor = "cor"
Colorinfos = namedtuple(classname_cor, fields_cor)
import pandas as pd
import numpy as np
from bs4 import BeautifulSoup

html = """
<div class="div1">
<p>hello</p>
<p>hi</p>
    <div class="nesteddiv">
        <p>one</p>
        <p>two</p>
        <p>three</p>
    </div>
</div>
"""

print(f"""{isiter({1:2,3:2}, )=}""")
print(f"""{isiter([1,2,34], )=}""")
print(f"""{isiter((1,2,34), )=}""")
print(f"""{isiter(Colorinfos(1,2,34,3,3), )=}""")
print(f"""{isiter(sorted((1,2,34,3,3)), )=}""")
print(f"""{isiter(({1, 2, 34, 3, 3}), )=}""")
print(f"""{isiter((55), )=}""")
print(f"""{isiter((55.44), )=}""")
print(f"""{isiter((True), )=}""")
print(f"""{isiter((3.14 + 2.71j), )=}""")
print(f"""{isiter((pd.DataFrame([[3,3,3],[3,3,3]])), )=}""")
print(f"""{isiter((pd.Series([[3,3,3]])), )=}""")
print(f"""{isiter((np.array([[3,3,3]])), )=}""")
print(f"""{isiter((np.ndarray([3,3,3])), )=}""")
print(f"""{isiter((pd.NA), )=}""")
print(f"""{isiter((np.nan), )=}""")
print(f"""{isiter(BeautifulSoup(html, 'lxml'), )=}""")
print(f"""{isiter(bytearray(b'dgfasds'), )=}""")
print(
    f"""{isiter(bytearray(b'dgfasds'),consider_non_iter=(str, bytes, bytearray) )=}"""
)
print(f"""{isiter(b'bababa', )=}""")
print(f"""{isiter(b'bababa',consider_non_iter=(str, bytes, bytearray) )=}""")
print(f"""{isiter('str1', )=}""")
print(f"""{isiter('str2',consider_non_iter=(str, bytes, bytearray))=}""")



{1: 2, 3: 2} in (list, tuple, set, frozenset, dict)
isiter({1:2,3:2}, )=True
[1, 2, 34] in (list, tuple, set, frozenset, dict)
isiter([1,2,34], )=True
(1, 2, 34) in (list, tuple, set, frozenset, dict)
isiter((1,2,34), )=True
cor(qt=1, rgb=2, r=3 in (list, tuple, set, frozenset, dict)
isiter(Colorinfos(1,2,34,3,3), )=True
[1, 2, 3, 3, 34] in (list, tuple, set, frozenset, dict)
isiter(sorted((1,2,34,3,3)), )=True
{1, 2, 3, 34} in (list, tuple, set, frozenset, dict)
isiter(({1, 2, 34, 3, 3}), )=True
55 in (int, float, bool, complex, type(None))
isiter((55), )=False
55.44 in (int, float, bool, complex, type(None))
isiter((55.44), )=False
True in (int, float, bool, complex, type(None))
isiter((True), )=False
(3.14+2.71j) in (int, float, bool, complex, type(None))
isiter((3.14 + 2.71j), )=False
   0  1  2
0  3  3   == Iterable
isiter((pd.DataFrame([[3,3,3],[3,3,3]])), )=True
0    [3, 3, 3]
dtype == Iterable
isiter((pd.Series([[3,3,3]])), )=True
array([[3, 3, 3]]) == Iterable
isiter((np.array([[3,3,3]])), )=True
array([[[6.23042070e == Iterable
isiter((np.ndarray([3,3,3])), )=True
<NA> not iter
isiter((pd.NA), )=False
nan in (int, float, bool, complex, type(None))
isiter((np.nan), )=False
<html><body><div cla == Iterable
isiter(BeautifulSoup(html, 'lxml'), )=True
bytearray(b'dgfasds' == Iterable
isiter(bytearray(b'dgfasds'), )=True
bytearray(b'dgfasds' in (<class 'str'>, <class 'bytes'>, <class 'bytearray'>)
isiter(bytearray(b'dgfasds'),consider_non_iter=(str, bytes, bytearray) )=False
b'bababa' == Iterable
isiter(b'bababa', )=True
b'bababa' in (<class 'str'>, <class 'bytes'>, <class 'bytearray'>)
isiter(b'bababa',consider_non_iter=(str, bytes, bytearray) )=False
'str1' == Iterable
isiter('str1', )=True
'str2' in (<class 'str'>, <class 'bytes'>, <class 'bytearray'>)
isiter('str2',consider_non_iter=(str, bytes, bytearray))=False

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

isiter-0.10.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

isiter-0.10-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file isiter-0.10.tar.gz.

File metadata

  • Download URL: isiter-0.10.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for isiter-0.10.tar.gz
Algorithm Hash digest
SHA256 8cc54796fe5204ab6e663c6d49369787aadd56d095f0b539f875ab3c02cc96bd
MD5 aa10c7fe07d09f96897bf7e9e731a9e7
BLAKE2b-256 282b375eca80f41b8fa7a068096f0fb942a2a3718e88e105509209139b9f15fe

See more details on using hashes here.

File details

Details for the file isiter-0.10-py3-none-any.whl.

File metadata

  • Download URL: isiter-0.10-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for isiter-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 252a0c669236ab1bd4d99f9f2294a81b6c3a24707a93d6774813d316dd5b0599
MD5 6bb281aa1d9e9d46776fea40ec97dc9d
BLAKE2b-256 c1457ac7e3812eea8253c1f9aaddb808d7c3e5631b2684b36f8c019a53919576

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page