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 16559
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: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |