Skip to content

Instantly share code, notes, and snippets.

@eclecticmiraclecat
Created October 10, 2020 02:59
Show Gist options
  • Save eclecticmiraclecat/042ea00b6eb7d66c3268bc181f28e1c5 to your computer and use it in GitHub Desktop.
Save eclecticmiraclecat/042ea00b6eb7d66c3268bc181f28e1c5 to your computer and use it in GitHub Desktop.
In [69]: package_details = ['Weight:', 2, 'Weight:', 4 ]
In [71]: package_details[::2]
Out[71]: ['Weight:', 'Weight:']
In [72]: package_details[1::2]
Out[72]: [2, 4]
In [73]: total_weight = sum(v for k, v in zip(package_details[::2], package_details[1::2]) if k == 'Weight:')
In [74]: total_weight
Out[74]: 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment