Python Forum
How to get index of minimum element between 3 & 8 in list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get index of minimum element between 3 & 8 in list
#1
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


Messages In This Thread
How to get index of minimum element between 3 & 8 in list - by Mekala - Nov-10-2020, 10:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  IndexError: list index out of range Laplace12 1 58 Yesterday, 10:47 AM
Last Post: Yoriz
  Convert each element of a list to a string for processing tester_V 6 356 Jun-16-2021, 02:11 AM
Last Post: tester_V
  IndexError: list index out of range brunolelli 11 911 Mar-25-2021, 11:36 PM
Last Post: brunolelli
  Changing Index of 2 List in python giddyhead 0 314 Mar-05-2021, 05:45 PM
Last Post: giddyhead
  IndexError: list index out of range ramu4651 2 534 Jan-24-2021, 01:45 PM
Last Post: buran
  How i can add elements to table index of element blazej2533 3 448 Dec-03-2020, 08:16 PM
Last Post: Larz60+
Question Matching variable to a list index Gilush 17 1,034 Nov-30-2020, 01:06 AM
Last Post: Larz60+
  Sume Every 10 element in the list and Divided of Sum quest_ 7 587 Nov-27-2020, 10:58 AM
Last Post: perfringo
  Counting Element in Multidimensional List quest_ 1 395 Nov-25-2020, 10:00 PM
Last Post: quest_
  Adding List Element if Second part of the List Elements are the Same quest_ 3 536 Nov-25-2020, 04:33 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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