Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unpacking zip object
#5
(Mar-24-2022, 09:32 PM)Mark17 Wrote: I have three (a, b, c) being unpacked to three (xp, yp, m).

But you don't have 3 elements in a,b,c, you have a total of 12. You can't put them into 3 variables with a single assignment. You could do that if you loop over them and change it each time.

Is this what you intend?

a = ['1-6-2017', '1-13-2017', '1-20-2017', '1-27-2017']
b = [265, -10, 130, 330]
c = ['d', '', 'd', '']


for xp, yp, m in zip(a, b, c):
    print(f"This time through the loop {xp=}, {yp=}, {m=}")
Output:
This time through the loop xp='1-6-2017', yp=265, m='d' This time through the loop xp='1-13-2017', yp=-10, m='' This time through the loop xp='1-20-2017', yp=130, m='d' This time through the loop xp='1-27-2017', yp=330, m=''
Mark17 likes this post
Reply


Messages In This Thread
Unpacking zip object - by Mark17 - Mar-24-2022, 06:52 PM
RE: Unpacking zip object - by bowlofred - Mar-24-2022, 07:41 PM
RE: Unpacking zip object - by Mark17 - Mar-24-2022, 09:32 PM
RE: Unpacking zip object - by Coricoco_fr - Mar-24-2022, 07:51 PM
RE: Unpacking zip object - by bowlofred - Mar-24-2022, 10:09 PM
RE: Unpacking zip object - by Mark17 - Mar-25-2022, 02:21 PM
RE: Unpacking zip object - by deanhystad - Mar-25-2022, 07:27 PM
RE: Unpacking zip object - by Mark17 - Mar-26-2022, 04:12 PM
RE: Unpacking zip object - by deanhystad - Mar-26-2022, 04:20 PM
RE: Unpacking zip object - by deanhystad - Mar-26-2022, 06:30 PM
RE: Unpacking zip object - by Mark17 - Mar-28-2022, 02:50 PM
RE: Unpacking zip object - by Mark17 - Mar-28-2022, 12:39 PM
RE: Unpacking zip object - by deanhystad - Mar-28-2022, 04:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Unpacking a dict with * or ** msrk 4 1,082 Dec-02-2023, 11:50 PM
Last Post: msrk
  iterate through the dict_values while unpacking the dictionary PeacockOpenminded 3 1,376 Jan-22-2023, 12:44 PM
Last Post: PeacockOpenminded
  unpacking list wardancer84 2 1,930 Sep-11-2021, 02:42 PM
Last Post: wardancer84
  unpacking tuple not working project_science 1 1,542 Jan-09-2021, 09:09 PM
Last Post: buran
  Unpacking a list Mark17 3 2,689 Dec-18-2020, 05:08 AM
Last Post: aajkaal
  Unpacking wheel files DavidTheGrockle 3 11,941 Dec-15-2020, 05:11 PM
Last Post: DavidTheGrockle
  Why the result of "extended iterable unpacking" with set() is unpredictable? zohanlin 2 2,141 Jun-29-2020, 10:30 AM
Last Post: zohanlin
  Unpacking nested lists yonatan776 1 2,251 Apr-14-2020, 08:50 PM
Last Post: buran
  Unpacking dictionary from .xlsx as Kwargs etjkai 5 2,966 Dec-27-2019, 05:31 PM
Last Post: etjkai
  Tuple Unpacking HarshaliPatel 3 2,922 Jan-30-2019, 12:42 PM
Last Post: dukoolsharma

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020