Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Iterating indexes of global values

Code
global x
global i
x.index(i) >= x.index(i+1)

I need x to include something other than i (i+1)

I need i to have an infinite number of iterations (probably sets)

I need both of those to be comparable size wise
I'm not quite sure what your trying to accomplish with this or why you need a global scope variable when you don't have any functions. Your code also does not make sense because x and i are not defined with anything. If your looking for an infinite number of iterations I would use a "while(True)" statement.

If your looking for something sort of similar to what you posted, maybe this is what your looking for?

Code
def main():

    #define your data
    x = [10,2,30,4,5]
    i = [2,4,6,8,10]

    #Iterate through every index of the first list
    for number in x:
        #Iterate through every index of the second list
        for other_number in i:
            #Comparison statement
            if number >= other_number:
                print(number, " : " ,other_number)
            else:
                pass
           
if __name__ == "__main__":
    main()
Cool. Now I have a type error:

Code
p = [set(), set(set())]
deter_g = ever_p[1]
print(deter_g)
#brings output: set()

add_set_inc = set()
ever_p = [add_set_inc]
add_set_count = 0

for add_set_count in range(len(ever_p)):
    add_set_inc = set(add_set_inc)
    ever_p.append(add_set_inc)
    add_set_count = add_set_count + 1
    if add_set_count == float('inf'):
        break
        
deter_g = ever_p[float('inf')]
print(deter_g)
#TypeError: list indices must be integers or slices, not float

How do I reference the end of the list?


(May 23, 2021 12:14 AM)Flash7475 Wrote:  I'm not quite sure what your trying to accomplish with this or why you need a global scope variable when you don't have any functions. Your code also does not make sense because x and i are not defined with anything. If your looking for an infinite number of iterations I would use a "while(True)"

The actual code (which is fire-walled by hack forums)
Does in fact have functions

The fact that the global variables are undefined confuses me... but it’s best to just stick to what the debugger is doing so I’m waiting for the NameError to pop up before I test that out and/or ask online.


I figured out the problem above

Use -1 to reference the end of a list


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Source] by HackersNov 19, 2024 01:51 PM 15 685 Nov 19, 2024 01:51 PM
Last Post: Hackers
[Python] by simmerDec 3, 2021 06:39 AM 4 175 Dec 3, 2021 06:39 AM
Last Post: simmer
[.NET] by PoppiecornNov 6, 2021 08:49 AM 1 173 Nov 6, 2021 08:49 AM
Last Post: donthakyou