lets say i have this list:
numbers = ['4', '3.2', '3.1', '3.15', '20', '3', '4', '17', '8']
and i want my script to tell me that the highest number in the list is '20'
how can i do that?
what if you wanted to find a number in the middle of that list: how would you go about that?
2 16550
what if you wanted to find a number in the middle of that list: how would you go about that?
Here's one way: -
>>> numbers = ('4', '3.2', '3.1', '3.15', '20', '3', '4', '17', '8')
-
>>> floatList = sorted([float(x) for x in numbers])
-
>>> floatList
-
[3.0, 3.1000000000000001, 3.1499999999999999, 3.2000000000000002, 4.0, 4.0, 8.0, 17.0, 20.0]
-
>>> average = sum(floatList)//len(floatList)
-
>>> average
-
7.0
-
>>> for i, item in enumerate(floatList):
-
... if item > average:
-
... print "%f is between %f and %f" %(average, item, floatList[i + 1])
-
... break
-
7.000000 is between 8.000000 and 17.000000
-
>>>
what if you wanted to find a number in the middle of that list: how would you go about that?
Or, if all you want is the number closest in position to the middle, then it's: -
>>> print floatList[len(floatList)/2]
-
4.0
-
>>>
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bob |
last post by:
I have been looking at the code for MedianFind(pDte As String) from the
following thread from UtterAccess.com: "Finding Median average grouped
by field"
I have been able to get it to run using...
|
by: nick.vitone |
last post by:
Hi,
I'm somewhat of a novice at Access, and I have no experience
programming whatsoever. I'm attempting to calculate the statistical
median in a query. I need to "Group by" one column and find...
|
by: ElkGroveR |
last post by:
Hi there!
I'm using PHP to create a simple, dynamic MySQL SELECT query.
The user chooses a selection from a HTML Form SELECT element's many options
and submits the form via a POST action.
...
|
by: erikcw |
last post by:
Hi all,
I have a collection of ordered numerical data in a list. The numbers
when plotted on a line chart make a low-high-low-high-high-low (random)
pattern. I need an algorithm to extract the...
|
by: Storm9 |
last post by:
I have to:
"Use functional decomposition to write a C++ program that determines the median of five input numbers. The median is the middle number when the five are arranged in order. However, the...
|
by: Bhadan |
last post by:
Hello,
I have several jagged arrays which have been sorted.
I'm trying to find the median of each array. Any tips appreciated.
TIA.
Bhads.
|
by: mehwishobaid |
last post by:
i dont know wat is wrong with my code. when i compile. i get the error
saying line 29: error: expression must have pointer-to-object type
#include <iostream>
using namespace std;
#include...
|
by: tomshorts07 |
last post by:
hi everyone!
i was wondering if anyone had any ideas on how to go about coding a method that would determine the median of a list of numbers
just to clarify- a median is the 'middle value' when...
|
by: curien |
last post by:
Hello,
I am working on a code that takes the users input ( a string of digits) from the command line and prints out the median number. I am trying to accomplish this by:
from sys import argv
...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
|
by: SueHopson |
last post by:
Hi All,
I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...
| |