Re: [Tutor] Assigning range :p:

2011-07-28 Thread Christopher King
On Wed, Jul 27, 2011 at 9:11 PM, Thomas C. Hicks para...@pobox.com wrote: On Wed, 27 Jul 2011 20:16:31 -0400 Alexander Quest alexxqu...@gmail.com wrote: x=range(1,50) mid=x[len(x)/2] You would have to make sure there is a way to work around decimal points in the division. Also, I would try

[Tutor] Assigning range

2011-07-27 Thread Alexander Quest
Does anyone know how to assign a certain numerical range to a variable, and then choose the number that is the middle of that range? For example, I want to assign the variable X a range between 1 and 50, and then I want to have the middle of that range (25) return with some command when I call it

Re: [Tutor] Assigning range

2011-07-27 Thread Steven D'Aprano
Alexander Quest wrote: Does anyone know how to assign a certain numerical range to a variable, and then choose the number that is the middle of that range? For example, I want to assign the variable X a range between 1 and 50, and then I want to have the middle of that range (25) return with

Re: [Tutor] Assigning range

2011-07-27 Thread Alexander Quest
Thanks Steven- I'll try that out. -Alex On Wed, Jul 27, 2011 at 5:40 PM, Steven D'Aprano st...@pearwood.infowrote: Alexander Quest wrote: Does anyone know how to assign a certain numerical range to a variable, and then choose the number that is the middle of that range? For example, I

Re: [Tutor] Assigning range :p:

2011-07-27 Thread Thomas C. Hicks
On Wed, 27 Jul 2011 20:16:31 -0400 Alexander Quest alexxqu...@gmail.com wrote: Does anyone know how to assign a certain numerical range to a variable, and then choose the number that is the middle of that range? For example, I want to assign the variable X a range between 1 and 50, and then I

Re: [Tutor] Assigning range

2011-07-27 Thread Donald Wilson
You could start with an anonymous function using the lambda operator, such as: mid_range = lambda x: x[len(x) // 2] Note: If you use len(x) / 2 in python 3.x you will get a TypeError because the division operator / returns a float.

Re: [Tutor] Assigning range

2011-07-27 Thread Alexander Quest
Thanks for that Donald! -Alex On Wed, Jul 27, 2011 at 8:16 PM, Donald Wilson donald...@me.com wrote: You could start with an anonymous function using the lambda operator, such as: mid_range = lambda x: x[len(x) // 2] Note: If