Created
November 14, 2020 16:54
-
-
Save chrisguox/030515515f64e38efced2066dee7991b to your computer and use it in GitHub Desktop.
response to https://www.v2ex.com/t/725192
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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