Source code for neurokit2.misc.listify
# -*- coding: utf-8 -*-
[docs]
def listify(**kwargs):
"""**Transforms arguments into lists of the same length**
Examples
--------
.. ipython:: python
import neurokit2 as nk
nk.listify(a=3, b=[3, 5], c=[3])
"""
args = kwargs
maxi = 1
# Find max length
for key, value in args.items():
if isinstance(value, str) is False:
try:
if len(value) > maxi:
maxi = len(value)
except TypeError:
pass
# Transform to lists
for key, value in args.items():
if isinstance(value, list):
args[key] = _multiply_list(value, maxi)
else:
args[key] = _multiply_list([value], maxi)
return args
def _multiply_list(lst, length):
q, r = divmod(length, len(lst))
return q * lst + lst[:r]