Bottom Page

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)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Parallel iteration with for loop Josh_Python890 1 166 Jul-19-2019, 11:50 PM
Last Post: metulburr
  Multiprocessing my Loop/Iteration (Try...Except) Jompie96 7 294 Jun-19-2019, 12:59 PM
Last Post: noisefloor
  file.write stops while true loop from executing in python3 boonr 3 333 Mar-25-2019, 12:50 PM
Last Post: ichabod801
  Python Thread stops execution neethuvp 1 307 Feb-18-2019, 06:36 PM
Last Post: micseydel
  randint stops changing values in a loop Naito 4 448 Jan-30-2019, 08:15 AM
Last Post: perfringo
  issue with updating list every iteration of a loop ftrillaudp 2 417 Oct-29-2018, 03:23 AM
Last Post: ftrillaudp
  exception during iteration loop Skaperen 6 598 Oct-24-2018, 12:35 AM
Last Post: Skaperen
  detect when scanner stops darter 1 488 Jun-29-2018, 10:07 PM
Last Post: Larz60+
  My code prints out my string 5 times and then just stops? Abstract_Otaku 0 424 Jun-13-2018, 07:11 PM
Last Post: Abstract_Otaku
  Looping issue, stops working JohnOsis 7 968 Apr-05-2018, 09:20 PM
Last Post: nilamo

Forum Jump:


Users browsing this thread: 1 Guest(s)