Python Forum
First for loop stops after first iteration
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
First for loop stops after first iteration
#7
(Apr-30-2019, 04:34 PM)buran Wrote: 30X20 would be 600 elements and you have 3200 (160x20). When you are reshaping, the total number of elements can’t be altered. That is why it works with break - f1 has 30 sub-lists and with brake it takes first element of each so you get 30x20 array to reshape
with the simplified example would you share what desired output would be and how it is achieved

f1 = [['N1M2', 'N1M3', 'N1M4', 'N1M5']]

f2 = ['M1N2','M1N3','M1N4','M1N5','M2N3','M2N4','M2N5','M3N4','M3N5','M4N5','N1M2','N1M3','N1M4','N1M5','N2M3','N2M4','N2M5','N3M4','N3M5','N4M5']
new = []
def get(f1, f2):
    for j in f1:
        for x in j:
            for i in f2:
                if i == x:
                    new.append('%s*1' % i)
                else:
                    new.append('%s*0' % i)
    return new
Output:
['M1N2*0', 'M1N3*0', 'M1N4*0', 'M1N5*0', 'M2N3*0', 'M2N4*0', 'M2N5*0', 'M3N4*0', 'M3N5*0', 'M4N5*0', 'N1M2*1', 'N1M3*0', 'N1M4*0', 'N1M5*0', 'N2M3*0', 'N2M4*0', 'N2M5*0', 'N3M4*0', 'N3M5*0', 'N4M5*0', 'M1N2*0', 'M1N3*0', 'M1N4*0', 'M1N5*0', 'M2N3*0', 'M2N4*0', 'M2N5*0', 'M3N4*0', 'M3N5*0', 'M4N5*0', 'N1M2*0', 'N1M3*1', 'N1M4*0', 'N1M5*0', 'N2M3*0', 'N2M4*0', 'N2M5*0', 'N3M4*0', 'N3M5*0', 'N4M5*0', 'M1N2*0', 'M1N3*0', 'M1N4*0', 'M1N5*0', 'M2N3*0', 'M2N4*0', 'M2N5*0', 'M3N4*0', 'M3N5*0', 'M4N5*0', 'N1M2*0', 'N1M3*0', 'N1M4*1', 'N1M5*0', 'N2M3*0', 'N2M4*0', 'N2M5*0', 'N3M4*0', 'N3M5*0', 'N4M5*0', 'M1N2*0', 'M1N3*0', 'M1N4*0', 'M1N5*0', 'M2N3*0', 'M2N4*0', 'M2N5*0', 'M3N4*0', 'M3N5*0', 'M4N5*0', 'N1M2*0', 'N1M3*0', 'N1M4*0', 'N1M5*1', 'N2M3*0', 'N2M4*0', 'N2M5*0', 'N3M4*0', 'N3M5*0', 'N4M5*0']
but the desired output is:
Output:
['M1N2*0', 'M1N3*0', 'M1N4*0', 'M1N5*0', 'M2N3*0', 'M2N4*0', 'M2N5*0', 'M3N4*0', 'M3N5*0', 'M4N5*0', 'N1M2*1', 'N1M3*1', 'N1M4*1', 'N1M5*1', 'N2M3*0', 'N2M4*0', 'N2M5*0', 'N3M4*0', 'N3M5*0', 'N4M5*0']
How could I get this?
Reply


Messages In This Thread
RE: First for loop stops after first iteration - by Divanova94 - May-01-2019, 01:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pip stops waiting for python walker 6 1,068 Nov-28-2023, 06:55 PM
Last Post: walker
  Inconsistent loop iteration behavior JonWayn 2 1,007 Dec-10-2022, 06:49 AM
Last Post: JonWayn
  [SOLVED] [Linux] Script in cron stops after first run in loop Winfried 2 937 Nov-16-2022, 07:58 PM
Last Post: Winfried
  Know when the pyttsx3 engine stops talking UsualCoder 3 3,239 Aug-29-2021, 11:08 PM
Last Post: snippsat
  saving each iteration of a loop sgcgrif3 3 6,744 Jul-27-2021, 01:02 PM
Last Post: DeaD_EyE
  IDLE stops responding upon saving tompi1 2 1,947 Oct-01-2020, 05:44 PM
Last Post: Larz60+
  String slicing and loop iteration divyansh 9 4,767 Jun-07-2020, 10:29 PM
Last Post: divyansh
  Python timer script stops before should ozstar 3 2,239 May-04-2020, 12:55 AM
Last Post: ozstar
  Python stops without errors shahgourav 4 2,783 Feb-04-2020, 11:44 PM
Last Post: micseydel
  Changing a variable's name on each iteration of a loop rix 6 84,845 Jan-03-2020, 07:06 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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