Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
compacting multiple ranges
#2
With such a small set of output values, the easiest approach is if-then-else statements:
Pseudocode:

if <s in range_1>:
return 1
elif <s in range_2>:
return 2
...

<s in range_1> could be implemented as one of these:

s in ('Alice',...,'Carol') # tuple
s in ['Alice',...,'Carol'] #list

If you had a much larger set of output values, it would be best to use a dict:
range_1 = {'Alice': 1,...,'Carol:1}

If you have both a reasonably large set of input and output values, you can just use a dict:
range = {'Alice':1,...,'Wanda':93}
Reply


Messages In This Thread
compacting multiple ranges - by Skaperen - Oct-09-2017, 01:52 AM
RE: compacting multiple ranges - by miltmobley - Oct-09-2017, 03:15 AM
RE: compacting multiple ranges - by Skaperen - Oct-11-2017, 08:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] [loop] Exclude ranges in… range? Winfried 2 4,056 May-14-2023, 04:29 PM
Last Post: Winfried
  Delete all Excel named ranges (local and global scope) pfdjhfuys 2 4,301 Mar-24-2023, 01:32 PM
Last Post: pfdjhfuys
  Dictionary with ranges that have a float step value Irv1n 2 2,834 Apr-21-2021, 09:04 PM
Last Post: Yoriz
  Two operations in two ranges salwa17 3 3,154 Jun-22-2020, 04:15 PM
Last Post: perfringo
  iterating a list of ranges Skaperen 1 2,684 May-22-2019, 07:44 AM
Last Post: Gribouillis
  Subnet Mask Ranges ab52 0 2,392 Mar-11-2019, 10:39 AM
Last Post: ab52
  joined ranges Skaperen 4 4,286 Apr-03-2018, 07:14 PM
Last Post: Gribouillis
  compacting a mutable sequence Skaperen 6 5,968 Jan-23-2018, 03:54 AM
Last Post: Skaperen
  a dictionary of ranges Skaperen 10 8,667 Dec-02-2017, 11:29 PM
Last Post: Windspar

Forum Jump:

User Panel Messages

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