Python Forum
Efficiency with regard to nested conditionals or and statements
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Efficiency with regard to nested conditionals or and statements
#4
Python can use anything in an if statement, not just boolean values or expressions that have a boolean result. A Python "and" or "or" may result in a non-boolean result, like a list or a string. That is why the nature of A, B and C are important in knowing how they can be used.

You could use the new (python 3.10) match statement
match control_flag:
    case "f1":
        # more tests
    case "fs":
        # more tests
If you are worried about efficiency you should not do lots of unnecessary conversions . Why int(float(datalist[2]))? You can compare a float(datalist[2]) against an int mte * 30. And I don't know if Python's code generator is smart enough to not evaluate float(datalist[6] thee times in this expression.
if float(datalist[6]) > float(datalist[3]) and float(datalist[6]) % 10 == 0 and float(datalist[6]) - float(datalist[3]) < 11:
Mark17 likes this post
Reply


Messages In This Thread
RE: Efficiency with regard to nested conditionals or and statements - by deanhystad - Apr-28-2022, 04:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Doubt about conditionals in Python. Carmazum 6 3,124 Apr-01-2023, 12:01 AM
Last Post: Carmazum
  Numpy Structure and Efficiency garynewport 2 1,375 Oct-19-2022, 10:11 PM
Last Post: paul18fr
  conditionals based on data frame mbrown009 1 1,569 Aug-12-2022, 08:18 AM
Last Post: Larz60+
  Nested conditionals vs conditionals connected by operators dboxall123 8 4,609 Feb-18-2022, 09:34 PM
Last Post: dboxall123
  Nested Conditionals shen123 3 3,442 Jul-28-2021, 08:24 AM
Last Post: Yoriz
  How to use vectorization instead of for loop to improve efficiency in python? PJLEMZ 4 3,421 Feb-06-2021, 09:45 AM
Last Post: paul18fr
  Invalid syntax using conditionals if - else jperezqu 1 2,987 Jan-13-2021, 07:32 PM
Last Post: bowlofred
  conditionals with boolean logic?? ridgerunnersjw 3 2,741 Sep-26-2020, 02:13 PM
Last Post: deanhystad
  two conditionals with intermediate code Skaperen 5 3,942 Jul-12-2020, 07:18 PM
Last Post: Skaperen
  Conditionals, while loops, continue, break (PyBite 102) Drone4four 2 4,099 Jun-04-2020, 12:08 PM
Last Post: Drone4four

Forum Jump:

User Panel Messages

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