Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create Dynamic For Loop
#1
Hello
My number of sublists is in this line:

        number_of_sublist=sum(len(x) for x in incoming)
      
And I want to create a for loop till the this number. For instance if number_of_sublist=2, then I need to create 2 forloop:
for x in incoming:
         for y in x:

If number_of_sublist=4, then I need to create 4 for loop like that:
for x in incoming:
    for y in x:
       for z in y:
        for t in z:
...    
How can I do that in an efficient way?
Reply


Messages In This Thread
Create Dynamic For Loop - by quest - Apr-26-2021, 10:55 AM
RE: Create Dynamic For Loop - by ndc85430 - Apr-26-2021, 12:56 PM
RE: Create Dynamic For Loop - by buran - Apr-26-2021, 02:00 PM
RE: Create Dynamic For Loop - by ibreeden - Apr-26-2021, 02:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to create a variable only for use inside the scope of a while loop? Radical 10 1,724 Nov-07-2023, 09:49 AM
Last Post: buran
  Creating a loop with dynamic variables instead of hardcoded values FugaziRocks 3 1,492 Jul-27-2022, 08:50 PM
Last Post: rob101
  loop for dynamic cut string - cleaner way? korenron 4 1,941 Nov-22-2021, 02:30 PM
Last Post: korenron
  Python Matplotlib: How do I save (in pdf) all the graphs I create in a loop? JaneTan 1 8,876 Feb-28-2021, 06:20 PM
Last Post: Larz60+
  how to create pythonic codes including for loop and if statement? aupres 1 1,926 Jan-02-2021, 06:10 AM
Last Post: Gribouillis
  create loop of subplot plotly dash without hardcode tonycat 0 3,918 Sep-23-2020, 08:40 AM
Last Post: tonycat
  Create tempfile that use in loop for insert into DB Firsttimepython 2 2,139 May-29-2020, 04:15 PM
Last Post: Firsttimepython
  Create, assign and print variables in loop steven_tr 10 4,356 May-28-2020, 04:26 PM
Last Post: ndc85430
  Mysql CREATE TABLE IF NOT EXISTS dynamic table name nisusavi 0 2,349 Apr-29-2020, 06:45 PM
Last Post: nisusavi
  Create a dynamic Menu from a editable Dictionary. KiNeMs 1 2,291 Jan-28-2020, 04:27 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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