I met a situation like this:
>>> li=['926.7', '930.6', '931.7', '933', '934.1', '936.5', '937.5', '940.5', '941.6', '944.6', '945.7', '947.2', '948.6', '950.4', '953.4', '957', '958.6', '962.1', '966.5', '968.2', '969.7', '970.4', '973.1', '974.6', '975.3', '983.9', '989.8', '996.5', '999.3', '1001.8', '1006.1', '1010.5', '1011.9', '1012.6', '1013.9', '1023.8', '1034.3', '1035.3', '1035.9', '1038.4', '1044.3', '1045.8', '1046.8', '1055.2', '1057.5', '1063.2', '1065', '1069.5', '1070.8', '1080', '1085', '1087.1', '1101.1', '1102', '1102.7', '1115.7', '1125.1', '1136.6']
>>> li
['926.7', '930.6', '931.7', '933', '934.1', '936.5', '937.5', '940.5', '941.6', '944.6', '945.7', '947.2', '948.6', '950.4', '953.4', '957', '958.6', '962.1', '966.5', '968.2', '969.7', '970.4', '973.1', '974.6', '975.3', '983.9', '989.8', '996.5', '999.3', '1001.8', '1006.1', '1010.5', '1011.9', '1012.6', '1013.9', '1023.8', '1034.3', '1035.3', '1035.9', '1038.4', '1044.3', '1045.8', '1046.8', '1055.2', '1057.5', '1063.2', '1065', '1069.5', '1070.8', '1080', '1085', '1087.1', '1101.1', '1102', '1102.7', '1115.7', '1125.1', '1136.6']
>>> max(li)
'999.3'
>>> min(li)
'1001.8'
>>>
I don't know why.
Can anyone answer me?
10 2076 bvdet 2,851
Expert Mod 2GB
A string evaluates different from a float or integer. - >>> "1000" > "999"
-
False
-
>>> 1000 > 999
-
True
-
>>>
bvdet
thank u!
nevertheless, how do I deal with situation like this, I store string of number in List
bvdet 2,851
Expert Mod 2GB
Your list is already sorted least value to largest value. li[0] is the minimum and li[-1] is the maximum.
Yes,this situation is special,but more are disorder, how to deal with those?
Store them as numbers instead of strings.
like this
[ '132.365', '132.148', '131.410', '131.237', '131.410', '130.586', '129.588', '128.330', '126.725', '124.686', '123.471', '124.122', '126.681', '129.545', '131.063', '131.410', '131.106', '130.499', '130.412', '130.456', '129.631', '127.853', '127.679', '129.588', '133.146', '135.228', '135.879', '135.879', '136.226', '137.788', '140.564', '143.818', '145.640', '146.464', '146.508', '145.423', '142.430', '138.525', '133.276', '128.330', '125.119', '122.820', '121.258', '119.436', '117.788', '116.269', '116.573', '117.614', '119.480', '121.128', '122.039', '121.345', '120.304', '119.349', '119.176', '119.263', '119.176', '118.829', '118.829', '119.393', '120.304', '120.781', '120.694', '120.391', '120.998', '122.126', '123.341', '123.341', '122.560', '122.516', '123.514', '124.425', '125.640', '127.462', '129.762', '131.020', '130.846', '129.154', '126.074', '123.601', '121.736', '120.955', '120.694', '120.868', '121.605', '123.080', '124.599', '125.076', '124.903', '124.599', '125.467', '126.725', '128.503', '130.282', '130.716', '130.022', '129.371', '128.634', '126.551', '124.078', '122.733', '122.386', '122.907', '124.469', '127.072', '128.634', '129.111', '129.284', '129.675', '130.152', '129.198', '127.506', '125.467', '124.642', '125.380', '125.814', '123.861', '118.829', '112.104', '108.156', '105.770', '102.820', '98.829', '96.573', '95.662', '95.011', '94.100', '93.753', '94.143', '94.360', '94.707', '94.317', '95.228', '97.961', '101.085', '103.818', '104.469', '103.471', '102.603', '102.777', '103.905', '104.642', '104.816', '104.555', '104.208', '104.208', '104.555', '105.033', '105.727', '106.681', '107.636', '109.284', '112.408', '115.662', '119.002', '120.868', '121.952', '122.820', '123.341', '124.382', '126.985', '131.323', '134.057', '134.881', '134.230', '132.451', '130.846', '129.111', '126.985', '125.336', '123.688', '121.432', '120.044', '119.176', '118.005', '116.226', '114.230', '110.673', '104.469', '100.608', '99.480', '100.130', '101.215', '101.866', '102.083', '102.126', '102.343', '102.690', '103.080', '103.775', '105.727', '108.634', '111.323', '113.970', '115.358', '115.792', '115.618', '115.792', '115.705', '114.577', '113.709', '113.362', '113.319', '113.059', '112.712', '112.712', '113.579', '114.360', '115.271', '116.703', '118.135', '118.091', '116.356', '114.057', '112.018', '110.673', '110.326', '110.890', '112.104', '113.059', '113.623', '114.013', '114.404', '115.488', '117.441', '119.436', '120.347', '120.434', '120.174', '120.087', '119.827']
but these numbers I read from txt, I am newbie
Don't use any quotes, quotes signify a string.
bvdet 2,851
Expert Mod 2GB
Your list of strings can be converted to a list of floats with a list comprehension. Or if you prefer to keep them as strings, you can sort the list to determine the max and min. - >>> [float(item) for item in s]
-
[800.89999999999998, 910.39999999999998, 999.89999999999998, 1000.4, 2000.0999999999999]
-
>>>
- >>> s = ["910.4", "1000.4", "800.9", "2000.1", "999.9"]
-
>>> s.sort(lambda a, b: cmp(float(a), float(b)))
-
>>> s
-
['800.9', '910.4', '999.9', '1000.4', '2000.1']
-
>>>
bvde's first solution maybe suitable , because I need the index of the max value in the list,I can't rearrange it and list[0] is stored a string of the series name.
I will try bvde's first solution
Sign in to post your reply or Sign up for a free account.
Similar topics
by: alexqa2003 |
last post by:
Table (continent,country,city,district,score)
a aa a1 g1a 100
a aa a1 g2a 99
a aa a1 g3a 99
a aa a1 f4d 89
a aa a1 f43 77
a aa a1...
|
by: Philipp |
last post by:
Dear CSS list reader,
IE6 does not support min-height, max-height. Is there a workaround for
the following problem?
http://www.scentech.ch/public/htmlcss/test1.html
The left cell - where is...
|
by: Ray in HK |
last post by:
I have 2 tables, they are daily and monthly tables.
I want to update the monthly table with the max and min value of the daily
table with the corresponding month.
I figure out the following...
|
by: Karl O. Pinc |
last post by:
I'd like to write:
SELECT larger(colA, colB) FROM foo
and am wondering the best way to go about it.
(Really, I'd like the larger() function to take an arbitrary
number of arguments but I...
|
by: damod.php |
last post by:
what is the life time(min, Max) of session variables,,
I want to know about sessions
whats session what is cookie whts the diff between
where the sessinon stored where the cookie stored
i want...
|
by: hypee |
last post by:
Hi,
Im relatively new to C programming and have an assignment due for next week
Task
Write a program which reads 10 numbers from a file "indata.txt", finds the minimum and maximum value,...
|
by: james121285 |
last post by:
I am having a problem with this program, I have been trying to do it all week and am stuck. I am writing a program that will take ten values from an input file, find the max and min then print them...
|
by: Yansky |
last post by:
Hi, just a quick question about the Math.min() function.
If I have an array of numbers:
var tempArray = ;
how come Math.min() can't look at all the numbers in the array at
once? i.e. - If I...
|
by: okonita |
last post by:
Hi all,
I need to create one or two indexes on date columns to support MAX and MIN aggregate functions on a very large table and to make the SQL perform/run faster. I remember a group discussion...
|
by: Eugeny Myunster |
last post by:
I know, only simple one:
#include <stdio.h>
int main()
{
int min=0,max=0,i,arr;
for(i=0;i<12;i++)
arr=rand()%31-10;
for(i=0;i<12;i++)
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
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: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
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: 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....
| |