Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8423669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:47:10+00:00 2026-06-10T03:47:10+00:00

I have two lists. The first list is already sorted (by some other criteria)

  • 0

I have two lists.

The first list is already sorted (by some other criteria) such that the earlier in the list, the better.

sortedList = ['200', '050', '202', '203', '206', '205', '049', '047', '042', '041', '043', '044', '046', '045', '210', '211', '306', '302', '308', '309', '311', '310', '221', '220', '213', '212']

The second list is a list of allowed values:

allowedList = ['001','002','003','004','005','006','007','008','009','010','203','204','205','206','207','212','213','215','216']

I would like to select the highest sorted value that exists in the allowedList, and I’m only coming up with silly ways of doing this. Things like this:

import numpy as np
temp = []
for x in allowedList:
    temp.append(sortedList.index(x))
np.min(temp)

There has to be a better way than this. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:47:11+00:00Added an answer on June 10, 2026 at 3:47 am

    The solutions using the fact that allowedlist is already sorted are probably more efficient (and using a set, they certainly are – linear time vs quadratic), but for completeness only, your existing solution can be shortened a lot and the temporary list eliminated:

    min(allowedList, key=sortedList.index)
    

    This uses Python’s built-in min function, rather than the one from numpy – np.min is mainly only useful if you’re using them with numpy arrays; there is no need for it when using lists.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two lists that i need to combine where the second list has
I have two list on my request on jsp. First one is productGroupName, and
I have two Lists, the firs (right) represents a list of all cars and
i have two dropdown list. first drop down:1 enter code here <form:select path=custName id=custName>
I have two ListBoxes. First ListBox items are list of Products. and second ListBox
I have two questions, actaully... First off, Why cant I do this: List<Object> object
Background I have two lists, the first is items which contains around 250 tuples,
I have two Lists, they look like this <List> ads [0] Headline = Sony
I have two lists. Ex: List<string> expected = new List<string>(); expected.Add( a ); expected.Add(
From previous queries, I have two variables. The first: <list> <item>a</item> <item>b</item> <item>a</item> <item>c</item>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.