Python Forum
Get the correct value when comparing with the list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get the correct value when comparing with the list
#1
Hi all,

I am working on my code as I am calculating with the button width size and the pixel in the area of the X in the screen to add it together to get the value. I'm trying to compare the value with the list when I'm calculating them to see if the value would come close, higher or equal to in the list.

Here is the code:

    CurrentRows = [375, 441, 507, 559, 610, 669, 724, 790, 838, 844, 849, 897, 910, 949, 959, 1009, 1016, 1018, 1019, 1072, 1125, 1138, 1184, 1186, 1189, 1238, 1246, 1286, 1419, 1620, 1762, 1840, 1943]
    
    nextprogram = int(program_id) + 1
    nextprogram1 = int(nextprogram) + 1
    nextprogram2 = int(nextprogram1) + 1
    nextprogram3 = int(nextprogram2) + 1
    program_button_1 = self.getControl(int(program_id))
    program_button_2 = self.getControl(int(nextprogram))
    program_button_3 = self.getControl(int(nextprogram1))
    program_button_4 = self.getControl(int(nextprogram2))
    pos_X = program_button_1.getX()
    
    width = program_button_1.getWidth()
    pos2_X = pos_X + width + 5
    print "program2 posX............................"
    print pos2_X
    program_button_2.setPosition(pos2_X, pos_Y)
    
    for pos_X1 in CurrentRows:
       if pos_X1 >= pos_X:
          pos_X = pos_X1
          break
    
    width = program_button_2.getWidth()
    pos3_X = pos2_X + width + 5
    print "program3 posX............................"
    print pos3_X
    program_button_3.setPosition(pos3_X, pos_Y)
When the variable pos_X show the value 1194, the closest one would be 1184. It is because 1194 went over 1184 so 1184 would be the correct value that I would use. If the value show 1253, the closest one would be 1246. When the value show 1125 that are matched from the list, I want to get 1125 from the list. 

How I could do that using with my code?

Thanks in advance!
Reply


Messages In This Thread
Get the correct value when comparing with the list - by chris0147 - Aug-04-2017, 12:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Comparing List values to get indexes Edward_ 7 1,246 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  Select correct item from list for subprocess command pythonnewbie138 6 3,374 Jul-24-2020, 09:09 PM
Last Post: pythonnewbie138
  Problem with comparing list palladium 2 2,178 Jul-08-2020, 10:49 AM
Last Post: DeaD_EyE
  comparing 2 dimensional list glennford49 10 4,236 Mar-24-2020, 05:23 PM
Last Post: saikiran
  What is the correct syntax for list items that need to contain a quotation mark, etc? KaisoArt 7 3,592 Sep-14-2019, 05:26 AM
Last Post: buran
  Looping through dictionary and comparing values with elements of a separate list. Mr_Keystrokes 5 3,956 Jun-22-2018, 03:08 PM
Last Post: wavic
  Create a new list by comparing values in a list and string DBS 2 3,575 Jan-14-2017, 07:59 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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