##### How to get index of minimum element between 3 & 8 in list
 How to get index of minimum element between 3 & 8 in list Mekala Not Blown Up Yet Posts: 67 Threads: 40 Joined: May 2020 Reputation: Nov-10-2020, 10:44 AM Hi, I have the below list, and I want to get the index of minimum element which is >3 & <=8. ```my_list = [-1,4,-5,0,2,11,9,8,6] #below only grep minimum whose value >0 m = min(i for i in my_list if i > 0) but I want a minimum element between 3 & 8 I use the below code, but it does not work. It still gives me an answer is 2. m2 = min(i for i in my_list if i > 0 & i<=8)```Someone help, how to achieve this. Reply Posts: 1,744 Threads: 8 Joined: Jun 2018 Reputation: Nov-10-2020, 10:50 AM (This post was last modified: Nov-10-2020, 10:50 AM by perfringo.) If your condition is `i > 0` then 2 is the correct answer. In order to avoid such typos it is more readable to write: ```>>> my_list = [-1,4,-5,0,2,11,9,8,6] >>> min(item for item in my_list if 3 < item <= 8) 4``` Mekala likes this post I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame. Reply DeaD_EyE Da Bishop Posts: 1,623 Threads: 6 Joined: May 2017 Reputation: Nov-10-2020, 12:56 PM A different form: ```def condition(x): return 3 < x <= 8 my_list = [-1,4,-5,0,2,11,9,8,6] minimum = min(filter(condition, my_list)) print("Minimum is", minimum)```I use it very rare. There are so many possibilities to solve this. My code examples are always for Python >=3.6.0 Almost dead, but too lazy to die: https://sourceserver.info All humans together. We don't need politicians! Reply

 Possibly Related Threads… Thread Author Replies Views Last Post Convert each element of a list to a string for processing tester_V 6 276 Today, 02:11 AM Last Post: tester_V IndexError: list index out of range brunolelli 11 843 Mar-25-2021, 11:36 PM Last Post: brunolelli Changing Index of 2 List in python giddyhead 0 296 Mar-05-2021, 05:45 PM Last Post: giddyhead IndexError: list index out of range ramu4651 2 518 Jan-24-2021, 01:45 PM Last Post: buran How i can add elements to table index of element blazej2533 3 438 Dec-03-2020, 08:16 PM Last Post: Larz60+ Matching variable to a list index Gilush 17 995 Nov-30-2020, 01:06 AM Last Post: Larz60+ Sume Every 10 element in the list and Divided of Sum quest_ 7 569 Nov-27-2020, 10:58 AM Last Post: perfringo Counting Element in Multidimensional List quest_ 1 382 Nov-25-2020, 10:00 PM Last Post: quest_ Adding List Element if Second part of the List Elements are the Same quest_ 3 520 Nov-25-2020, 04:33 PM Last Post: bowlofred Removing element from list squall 6 663 Nov-22-2020, 09:34 PM Last Post: jefsummers

Forum Jump:

### User Panel Messages

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