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
#11
f1 = [['N1M2', 'N1M3', 'N1M4', 'N1M5'], ['M1N2', 'N2M3', 'N2M4', 'N2M5']]
f2 = ['M1N2','M1N3','M1N4','M1N5','M2N3','M2N4','M2N5','M3N4','M3N5','M4N5','N1M2','N1M3','N1M4','N1M5','N2M3','N2M4','N2M5','N3M4','N3M5','N4M5']

new = []
for sub_list in f1:
    new_sublist = []
    for item in f2:
        new_item = f'{item}*{int(item in sub_list)}'
        new_sublist.append(new_item)
    new.append(new_sublist)
        
print(new)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Know when the pyttsx3 engine stops talking UsualCoder 3 659 Aug-29-2021, 11:08 PM
Last Post: snippsat
  saving each iteration of a loop sgcgrif3 3 1,577 Jul-27-2021, 01:02 PM
Last Post: DeaD_EyE
  IDLE stops responding upon saving tompi1 2 860 Oct-01-2020, 05:44 PM
Last Post: Larz60+
  String slicing and loop iteration divyansh 9 2,570 Jun-07-2020, 10:29 PM
Last Post: divyansh
  Python timer script stops before should ozstar 3 1,110 May-04-2020, 12:55 AM
Last Post: ozstar
  Python stops without errors shahgourav 4 1,340 Feb-04-2020, 11:44 PM
Last Post: micseydel
  Changing a variable's name on each iteration of a loop rix 6 36,030 Jan-03-2020, 07:06 AM
Last Post: perfringo
  Parallel iteration with for loop Josh_Python890 1 1,276 Jul-19-2019, 11:50 PM
Last Post: metulburr
  Multiprocessing my Loop/Iteration (Try...Except) Jompie96 7 2,603 Jun-19-2019, 12:59 PM
Last Post: noisefloor
  file.write stops while true loop from executing in python3 boonr 3 1,649 Mar-25-2019, 12:50 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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