A small library used to obtain types for various builtin iterators.
Project description
IterTypes Library
This library has some useful types and functions used to get types of iterables. Whilst iterable types were purposely avoided by the types library, iterables offer unique types which could sometimes be useful to obtain.
Getting started
Start by importing the module:
import itertypes
There are various functions which follow the naming convention is[type]iterator
.
itertypes.isstringiterator(iter("string"))
>>> True
dictionary = {1: 2, 3: 4}
iteration = iter(dictionary.items())
itertypes.isdictitemiterator(iteration)
>>> True
There's also the itertypes.isiterator
function where it checks if the given
object is iterable or not.
my_variable = 5
itertypes.isiterable(my_variable)
>>> False
my_variable = ['a', 'b', 'c', 'd']
all([itertypes.isiterable(my_variable), itertypes.islistiterator(iter(my_variable))])
>>> True
Finally, there's various types which resolve to iterable types. These types can be used with isinstance, or with the equality operator and the type function.
byte = bytearray()
isinstance(iter(byte), itertypes.BytearrayIteratorType)
>>> True
iterable = iter({1: 2, 3: 4}.values())
isinstance(iterable, itertypes.DictValueIteratorType)
>>> True
Installation
Install through pip.
python -m pip install itertypes
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
Built Distribution
Hashes for itertypes-1.6.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7069f572b0f0328500577489cbfdf77f63a486508fb6523c8e662f5d43eb05f5 |
|
MD5 | ddefc8d98d7079913fc6ddfe44b7681d |
|
BLAKE2b-256 | b8780463c4d0cec51fb9c11d5acb147f996842546cd5c92a5b0f107aeb64852b |