just a quick question here. i need to write a function written in python that receives a list of numbers and two values and returns the number of items between those two values. for example if the list is [1,2,3,4] and the two values are 2 and 4 then the function would return 3.
all i have so far is the very beginning
def main():
listdata = raw_input("please enter a string of numbers")
surroundnum = raw_input("enter two values in the list")
im not really sure how that helps.... i mean i dont understand how that gets the number in between two given numbers in the list. all i get when i use that code is sets of numbers from the list divided into pairs
But I have a question for you. What do you mean by between. There are two scenarios.
1. Give me all numbers that are greater than 2 and smaller than 4 in the given list. Or
2. Give me all numbers that are physically located between numbers 2 and 4 in the given list. Example:
[6, 2, 5, 4] would return 5.
Given scenario 2, that would be why dwblas is refering to location in the list...
i meant the physical location im just not sure how the hint applies. i mean i get the list,and the two numbers. i just dont know how to get the two to interact and then pull the number between them
Once you found the locations, you basically have a lower and upper limit. You should read about slicing a list as well as the index property of a list.
Some more hints:
Expand|Select|Wrap|Line Numbers
test_list=[6, 2, 5, 4]
x=test_list.index("2")
y=test_list.index("4")
z=test_list[x:y] #or probably x+1 and y-1... may need some validation