Python Forum
Define a range, return all numbers of range that are NOT in csv data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Define a range, return all numbers of range that are NOT in csv data
#16
Oh, sorry. You need to actually call the check_range function to start the whole thing. And 'number' on line 21 should be 'n' (or 'n' on line 20 should be 'number').

As long as _num_ranges is not empty, num_range will be defined when it gets to line 27. The loop variable num_range is what you are checking with in_range(). If it's valid, the loop breaks, and then what you return is the valid range.

However, come to think of it, there is the possibility that a valid range is not found. In that case, find_range will return the last range, even if it's not valid (because that will be the value after the loop is done). You could fix that with an else:

def find_range(n):
    for num_range in _number_ranges.values():
        if in_range(n, num_range):
            return num_range
    else:
        return None
Returning it within the loop might shut up that warning message you are getting.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: Define a range, return all numbers of range that are NOT in csv data - by ichabod801 - Jan-06-2020, 03:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades 8 15,887 Jan-05-2024, 08:30 PM
Last Post: sgrey
  [SOLVED] [loop] Exclude ranges in… range? Winfried 2 1,590 May-14-2023, 04:29 PM
Last Post: Winfried
Thumbs Down I hate "List index out of range" Melen 20 3,548 May-14-2023, 06:43 AM
Last Post: deanhystad
  How to check multiple columns value within range SamLiu 2 1,242 Mar-13-2023, 09:32 AM
Last Post: SamLiu
  Expand the range of a NumPy array? PythonNPC 0 794 Jan-31-2023, 02:41 AM
Last Post: PythonNPC
  Copying files if the name is in range tester_V 9 1,678 Nov-24-2022, 12:21 AM
Last Post: tester_V
Exclamation IndexError: Replacement index 2 out of range for positional args tuple - help? MrKnd94 2 6,715 Oct-14-2022, 09:57 PM
Last Post: MrKnd94
  Solving an equation by brute force within a range alexfrol86 3 2,901 Aug-09-2022, 09:44 AM
Last Post: Gribouillis
  IndexError: list index out of range dolac 4 1,994 Jul-25-2022, 03:42 PM
Last Post: deanhystad
  I'm getting a String index out of range error debian77 7 2,422 Jun-26-2022, 09:50 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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