Skip to content

Instantly share code, notes, and snippets.

@chrisguox
Created November 14, 2020 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisguox/030515515f64e38efced2066dee7991b to your computer and use it in GitHub Desktop.
Save chrisguox/030515515f64e38efced2066dee7991b to your computer and use it in GitHub Desktop.
def chunk(iterable_obj, n):
assert n > 0, "n must be greater than zero"
while iterable_obj:
yield iterable_obj[:n]
iterable_obj = iterable_obj[n:]
def generate_ft_struct(fs, ts):
return [
{
f"f{i}": f,
f"t{i}": t
}
for i, (f, t) in enumerate(zip(fs, ts), 1)
]
a = [1, 2, 3, 4]
b = ["a", "b", "c", "d"]
nums = 2
chunk_a = chunk(a, nums)
chunk_b = chunk(b, nums)
res = [generate_ft_struct(fs, ts) for fs, ts in zip(chunk_a, chunk_b)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment