Python Forum
Python2.7 xrange for loops - repeating though values already considered?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python2.7 xrange for loops - repeating though values already considered?
#1
Each g in g_values for the minimal code below is being looped through, however when the end of g_values is reached, the outside loop starts again. I can tell this since concat_g_p starts from 2_3 again.

I would like an explanation as to why this happens, and suggestions on what to do to fix it?

Minimal code:
g_values=xrange(2,3)
p_values=primes[0:1000]
h_values=xrange(2,100)
order_false_list=[]

for g in g_values:
    for p in p_values:
        concat_g_p=str(g)+"_"+str(p)
        print "concat_g_p is: "+str(concat_g_p)
        if concat_g_p in order_false_list:
            break
        elif g == p:
            ...
        else:
            for h in h_values:
                if h>=p:
                    #don't want to consider these since solutions of these already dealt with (non-unique)
                    h_solution_found=True
                    break
                else:
                    ...
                    order_false_list.append(concat_g_p)
...
Reply
#2
please make code executable so testing can be done
Reply
#3
I can't edit my post since past the 10min time limit. I presume I need to repost?
Reply
#4
You'll be able to edit after only a few posts.
Just re-post no one will chastise you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is 2/3 not just .666 repeating? DocFro 4 691 Dec-12-2023, 09:09 AM
Last Post: buran
  repeating a user_input astral_travel 17 2,264 Oct-26-2022, 04:15 PM
Last Post: astral_travel
  if else repeating Frankduc 12 2,491 Jul-14-2022, 12:40 PM
Last Post: Frankduc
  matching a repeating string Skaperen 2 1,236 Jun-23-2022, 10:34 PM
Last Post: Skaperen
  Random Number Repeating Tzenesh 5 4,021 Jan-13-2021, 10:00 PM
Last Post: deanhystad
  factorial, repeating Aldiyar 4 2,789 Sep-01-2020, 05:22 PM
Last Post: DPaul
  number repeating twice in loop JonnyEnglish 3 3,307 Nov-24-2019, 09:23 AM
Last Post: ThomasL
  Trying to run a python2 script dagamer1991 3 2,534 Aug-12-2019, 12:33 PM
Last Post: buran
  Repeating equations Tbot100 2 3,258 May-29-2019, 02:38 AM
Last Post: heiner55
  python2.7 executables thus the system python2.7 was erroring utility.execute()? vivekm 1 1,755 May-20-2019, 11:24 AM
Last Post: vivekm

Forum Jump:

User Panel Messages

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