Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
maintaining list order
#10
Sure no problem.

I'm looping through my list and find 3 items (also lists):

Listitem 1: [3]
check if "3" is larger than a value in list [0,3000,6000]. If it's larger: return that compared value.

3 > 6000 ? no
3 > 3000 ? no
3 > 0 ? yes, return [0]

Listitem 2: [4:400]
check if "4" is larger than a value in list [0,3000,6000]. If it's larger: return that compared value.

4 > 6000 ? no
4 > 3000 ? no
4 > 0 ? yes, return 0

check if "400" is larger than a value in list [0,3000,6000]. If it's larger: return that compared value.

400 > 6000 ? no
400 > 3000 ? no
400 > 0 ? yes, return 0

These two items combined as returned value [0, 0]

Listitem 3: [3:4222]
check if "3" is larger than a value in list [0,3000,6000]. If it's larger: return that compared value.

3 > 6000 ? no
3 > 3000 ? no
3 > 0 ? yes, return 0

check if "4222" is larger than a value in list [0,3000,6000]. If it's larger: return that compared value.

4222 > 6000 ? no
4222 > 3000 ? yes, return 3000
don't test the rest, I'm satisfied with this result.

These two items combined as returned value [0, 3000]

Combined return should be a list therefor: [ [0], [0, 0], [0, 3000] ]
Reply


Messages In This Thread
maintaining list order - by 3Pinter - May-29-2019, 10:06 AM
RE: maintaining list order - by perfringo - May-29-2019, 10:32 AM
RE: maintaining list order - by 3Pinter - May-29-2019, 12:08 PM
RE: maintaining list order - by perfringo - May-29-2019, 12:37 PM
RE: maintaining list order - by 3Pinter - May-29-2019, 12:45 PM
RE: maintaining list order - by buran - May-29-2019, 12:48 PM
RE: maintaining list order - by 3Pinter - May-29-2019, 01:07 PM
RE: maintaining list order - by perfringo - May-29-2019, 01:18 PM
RE: maintaining list order - by michalmonday - May-29-2019, 01:43 PM
RE: maintaining list order - by 3Pinter - May-29-2019, 01:53 PM
RE: maintaining list order - by michalmonday - May-29-2019, 02:13 PM
RE: maintaining list order - by 3Pinter - May-29-2019, 02:35 PM
RE: maintaining list order - by perfringo - May-29-2019, 07:01 PM
RE: maintaining list order - by 3Pinter - Jun-05-2019, 07:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Copying the order of another list with identical values gohanhango 7 1,316 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,478 May-22-2023, 10:39 PM
Last Post: ICanIBB
  Order a list with successive permutations based on another list yvrob 3 2,914 Mar-19-2021, 08:20 AM
Last Post: supuflounder
  Group List Elements according to the Input with the order of binary combination quest_ 19 6,769 Jan-28-2021, 03:36 AM
Last Post: bowlofred
  list approach due nested order 3Pinter 6 2,938 Oct-07-2019, 01:49 PM
Last Post: 3Pinter
  How to count and order numbers in a list rachyioli 2 2,660 Aug-21-2019, 10:51 AM
Last Post: perfringo
  Randomise network while maintaining topology of nodes using edge-swap approach Tom1988 3 4,224 May-25-2017, 10:59 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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