mirror of
https://github.com/pret/pokemon-reverse-engineering-tools.git
synced 2026-08-24 03:04:08 -05:00
better docstrings in helpers.py
This commit is contained in:
@@ -4,18 +4,25 @@ Generic functions that should be reusable anywhere in pokemontools.
|
||||
import os
|
||||
|
||||
def index(seq, f):
|
||||
"""return the index of the first item in seq
|
||||
where f(item) == True."""
|
||||
"""
|
||||
return the index of the first item in seq
|
||||
where f(item) == True.
|
||||
"""
|
||||
return next((i for i in xrange(len(seq)) if f(seq[i])), None)
|
||||
|
||||
def grouper(some_list, count=2):
|
||||
"""splits a list into sublists
|
||||
"""
|
||||
splits a list into sublists
|
||||
|
||||
given: [1, 2, 3, 4]
|
||||
returns: [[1, 2], [3, 4]]"""
|
||||
returns: [[1, 2], [3, 4]]
|
||||
"""
|
||||
return [some_list[i:i+count] for i in range(0, len(some_list), count)]
|
||||
|
||||
def flattener(x):
|
||||
"flattens a list of sublists into just one list (generator)"
|
||||
"""
|
||||
flattens a list of sublists into just one list (generator)
|
||||
"""
|
||||
try:
|
||||
it = iter(x)
|
||||
except TypeError:
|
||||
@@ -26,7 +33,9 @@ def flattener(x):
|
||||
yield j
|
||||
|
||||
def flatten(x):
|
||||
"flattens a list of sublists into just one list"
|
||||
"""
|
||||
flattens a list of sublists into just one list
|
||||
"""
|
||||
return list(flattener(x))
|
||||
|
||||
def mkdir_p(path):
|
||||
|
||||
Reference in New Issue
Block a user