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 1,750 Dec-12-2023, 09:09 AM
Last Post: buran
  repeating a user_input astral_travel 17 4,774 Oct-26-2022, 04:15 PM
Last Post: astral_travel
  if else repeating Frankduc 12 4,534 Jul-14-2022, 12:40 PM
Last Post: Frankduc
  python2 python3 messed up : How to fix ? hary 15 11,225 Dec-30-2020, 08:26 PM
Last Post: hary
  factorial, repeating Aldiyar 4 3,817 Sep-01-2020, 05:22 PM
Last Post: DPaul
  using pudb on python2 code ErnestTBass 2 2,365 Aug-10-2020, 08:12 PM
Last Post: snippsat
  Trying to run a python2 script dagamer1991 3 3,319 Aug-12-2019, 12:33 PM
Last Post: buran
  Repeating equations Tbot100 2 4,066 May-29-2019, 02:38 AM
Last Post: heiner55
  python2.7 executables thus the system python2.7 was erroring utility.execute()? vivekm 1 2,305 May-20-2019, 11:24 AM
Last Post: vivekm
  Python2 is not supported Skaperen 2 2,949 Mar-01-2019, 07:50 PM
Last Post: stranac

Forum Jump:

User Panel Messages

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