Skip to content

Instantly share code, notes, and snippets.

@sebastianschramm
Created August 29, 2022 13:11
Show Gist options
  • Save sebastianschramm/8304e15472ee8bf37a840abefa395460 to your computer and use it in GitHub Desktop.
Save sebastianschramm/8304e15472ee8bf37a840abefa395460 to your computer and use it in GitHub Desktop.
How to use zip with strict since py3.10
names = ['a', 'b', 'c']
values = [10, 54, 2]
values_too_long = values + [10]
"""
>>> {k: v for k, v in zip(names, values_too_long, strict=True)}
ValueError: zip() argument 2 is longer than argument 1
>>> {k: v for k, v in zip(names, values_too_long, strict=False)}
{'a': 10, 'b': 54, 'c': 2}
>>> {k: v for k, v in zip(names, values, strict=True)}
{'a': 10, 'b': 54, 'c': 2}
"""
@sebastianschramm
Copy link
Author

dependencies: python3.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment