Python Forum
Comparing List values to get indexes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Comparing List values to get indexes
#1
I'm trying to compare a short temporary list of values to a master list, to obtain the index number (of short list items) and set two variable values based on the index values being <= 10 or >10.

So when I have an index <=10 set out1 = 1, indexes >10 set out2 value to 1.
If no <=10 index values found, out1 = 0, no index values for >10, out2 = 0.

Here's my code that outputs: out1: 1, out2: 1, but expected out1: 1, out2: 0 based on the example list values.
(if the onList[] is empty during use, the zoneRefresh() function won't be called.)

aList = ["Bin 1", "Bin 2", "Bin 3", "Bin 4", "Bin 5","Bin 6", "Bin 7", "Bin 8", "Bin 9", "Bin 10", "Bin 11",
        "Bin 12", "Bin 13", "Bin 14", "Bin 15"]
onList = ["Bin 3", "Bin 4"] #For test, usually empty
  
def zoneRefresh():
    out1 = 0
    out2 = 0
    for i in range(len(aList)):
        if aList[i] in onList:
            if(i) <= 10:
                out1 = 1
                print("out1: " + str(out1))
            else: # (i) > 10
                out2 = 1
                print("out2: " + str(out2))
I can't see why the out2 varible is assigned a "1" when there is no value with an index greater-than 10 in the onList[].
Any assistance appreciated.
Reply


Messages In This Thread
Comparing List values to get indexes - by Edward_ - Jun-08-2023, 03:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Assigning cycle values in a list nmancini 3 965 Sep-16-2024, 09:35 PM
Last Post: deanhystad
  remove duplicates from dicts with list values wardancer84 27 5,590 May-27-2024, 04:54 PM
Last Post: wardancer84
  Copying the order of another list with identical values gohanhango 7 2,525 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 2,774 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Adding values with reduce() function from the list of tuples kinimod 10 5,382 Jan-24-2023, 08:22 AM
Last Post: perfringo
  user input values into list of lists tauros73 3 1,950 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  Replace columns indexes reading a XSLX file Larry1888 2 1,702 Nov-18-2022, 10:16 PM
Last Post: Pedroski55
  AttributeError: 'list' object has no attribute 'values' ilknurg 4 20,703 Jan-19-2022, 08:33 AM
Last Post: menator01
  Need to parse a list of boolean columns inside a list and return true values Python84 4 3,167 Jan-09-2022, 02:39 AM
Last Post: Python84
  List of dataframe values beginning with x,y or z glidecode 3 2,744 Nov-08-2021, 10:16 PM
Last Post: glidecode

Forum Jump:

User Panel Messages

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