简体   繁体   中英

In Python, is there a build-in function to get the values (in list) between two given ones?

Is there a built-in function to get the values (in list) between two given ones? For example, let LIST be a Python list defined as:

LIST=[value_1, value_2, value_3,...,value_n]

how to find the elements between (for example) value_p and value_k , where p is less than k , and p, k both belong to the interval [0,n]

Using list slicing

arr = [1,2,3,4,5,6,7]
arr[3:6]

output:

[4, 5, 6]

here 3 is p and 6 is k

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM