Python Forum
sort lists of lists with multiple criteria: similar values need to be treated equal
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sort lists of lists with multiple criteria: similar values need to be treated equal
#2
Well, you haven't defined what you mean by similar. Obviously you know how to sort using key functions. If you can define a function such that all similar values get transformed into the same value, you can just use a key function. For example, if you want to ignore the ones digit, you could just use lambda x: x[1] // 10, x[0].

But say your similarity is "within 10 of the next value". That you can't define a simple function for. You may need to augment your lists with a fourth value. That is, sort by y. Then add a fourth item to each sublist that is the same as the previous sublist's fourth value if they are within 10 of each other, otherwise it's one greater. Then sort by the fourth item and the first item (x).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: sort lists of lists with multiple criteria: similar values need to be treated equal - by ichabod801 - Mar-20-2019, 03:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare lists w_i_k_i_d 4 233 May-18-2024, 04:03 PM
Last Post: Pedroski55
Question Using Lists as Dictionary Values bfallert 8 522 Apr-21-2024, 06:55 AM
Last Post: Pedroski55
  __init__() got multiple values for argument 'schema' dawid294 4 2,810 Jan-03-2024, 09:42 AM
Last Post: buran
  filtering a list of dictionary as per given criteria jss 5 780 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  problem with print lists MarekGwozdz 4 779 Dec-15-2023, 09:13 AM
Last Post: Pedroski55
  python convert multiple files to multiple lists MCL169 6 1,692 Nov-25-2023, 05:31 AM
Last Post: Iqratech
  find the sum of a series of values that equal a number ancorte 1 548 Oct-30-2023, 05:41 AM
Last Post: Gribouillis
  Lists blake7 6 883 Oct-06-2023, 12:46 PM
Last Post: buran
  Trying to understand strings and lists of strings Konstantin23 2 848 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Why do the lists not match? Alexeyk2007 3 899 Jul-01-2023, 09:19 PM
Last Post: ICanIBB

Forum Jump:

User Panel Messages

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