Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3238900
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:54:26+00:00 2026-05-17T17:54:26+00:00

Sorry to double my earlier question, but I thought to ask specific data which

  • 0

Sorry to double my earlier question, but I thought to ask specific data which would solve the problem. I want this result

tuple_of_vars = (item for _, item for zip(tuple_of_vars, new_vals_generator))

as this is not possible

a, b, c, d = (val for val in infite_generator)

actually then I want to do in single line

for var in var_list:
    var = next(infinite_generator)

Is there any interpreter hook to take metainformation of number of vars at left hand side of assignement? Better would be though that I could just do automatically this last bit of code (including cases with left side which is slice with variable indexes and step)

Also is there way to make generator of variables which would be left hands side of assignment.

EDIT: This does not stop in Python3:

def incr(a):
    while True:
        yield a
        a += 1


a = [None for i in range(20)]

a[3:3:3], *_ = incr(1)

print(a)

Same with:

a,b,c,d, *_ = incr(1)

print(a, b, c, d)

Even it has not slice (actually the indexes would be variables, this is only test). I am aware of islice etc but it is too slow.

This produce also error:

a = 1000*[True]

bound = int(len(a) ** 0.5)

for i in range(3, bound, 2):
    a[3::i], *x = [[False] for _ in range(bound)]

""" Error:
ValueError: attempt to assign sequence of size 1 to extended slice of size 333
"""

And this:

a = 1000*[True]

bound = int(len(a) ** 0.5)

for i in range(3, bound, 2):
    a[3::i], *x = [False] * bound

""" Error:
TypeError: must assign iterable to extended slice
"""
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:54:26+00:00Added an answer on May 17, 2026 at 5:54 pm

    When you know the var_list‘s length, you could use itertools.islice to cut off the infinite generator:

    >>> import itertools
    >>> infgen = itertools.cycle([1,4,9])
    >>> a,b,c,d = itertools.islice(infgen, 4)
    >>> a,b,c,d
    (1, 4, 9, 1)
    

    It works for assignment to a slice of list too.

    >>> lst = [0]*20
    >>> lst[2:10:2] = itertools.islice(infgen, 4)
    >>> lst
    [0, 0, 4, 0, 9, 0, 1, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry, for double posting, already posted this question once, but I realized I weren't
Sorry for this not being a real question, but Sometime back i remember seeing
Sorry if this sounds like a really stupid question, but I need to make
Sorry for the double post, I will update this question if I can't get
Sorry if this is a newbie question. I have searched but found nothing... Using
Sorry for the second newbie question, I'm a developer not a sysadmin so this
Sorry for what seems like a silly question: But I've never, ever worked with
sorry for the cryptic question title. I'm having a strange problem and i have
I'm having problem with double linked lists: I can't get data from nodes throgh
This is probably a very silly and simple question to most of you, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.