2
$\begingroup$

If I have a list such as:

list={40,40.,40.,40.,40.0001,40.0001,40.0001,40.0002,40.0002,40.0003,40.0003,40.0004,40.0005,40.0005,40.0006,40.0007,40.0008,40.0009,40.001,40.0011,40.0013,40.0014,40.0015,40.0017,40.0018,40.002,40.0021,40.0023,40.0024,40.0026,40.0028,40.003,40.0032,40.0034,40.0036,40.0038,40.004,40.0042,40.0044,40.0047,40.0049,40.0052,40.0054,40.0057,40.0059,40.0062,40.0065,40.0068,40.0071,40.0074,40.0077,40.008,40.0083,40.0086,40.0089,40.0092,40.0096,40.0099,40.0103,40.0106,40.011,40.0113,40.0117,40.0121,40.0125,40.0129,40.0133,40.0137,40.0141,40.0145,40.0149,40.0153,40.0158,40.0162,40.0167,40.0171,40.0176,40.018,40.0185,40.019,40.0194,40.0199,40.0204,40.0209,40.0214,40.0219,40.0224,40.023,40.0235,40.024,40.0246,40.0251,40.0257,40.0262,40.0268,40.0274,40.0279,40.0285,40.0291,40.0297,40.0303,40.0309,40.0315,40.0321,40.0328,40.0334,40.034,40.0347,40.0353,40.036,40.0366,40.0373,40.038,40.0386,40.0393,40.04,40.0407,40.0414,40.0421,40.0428,40.0436,40.0443,40.045,40.0458,40.0465,40.0473,40.048,40.0488,40.0495,40.0503,40.0511,40.0519,40.0527,40.0535,40.0543,40.0551,40.0559,40.0567,40.0575,40.0584,40.0592,40.0601,40.0609,40.0618,40.0626,40.0635,40.0644,40.0653,40.0662,40.0671,40.068,40.0689,40.0698,40.0707,40.0716,40.0725,40.0735,40.0744,40.0754,40.0763,40.0773,40.0782,40.0792,40.0802,40.0812,40.0822,40.0832,40.0842,40.0852,40.0862,40.0872,40.0882,40.0893,40.0903,40.0914,40.0924,40.0935,40.0945,40.0956,40.0967,40.0977,40.0988,40.0999,40.101,40.1021,40.1032,40.1043,40.1055,40.1066,40.1077,40.1089,40.11,40.1112,40.1123,40.1135,40.1147,40.1158,40.117,40.1182,40.1194,40.1206,40.1218,40.123,40.1242,40.1255,40.1267,40.1279,40.1292,40.1304,40.1317,40.1329,40.1342,40.1355,40.1367,40.138,40.1393,40.1406,40.1419,40.1432,40.1445,40.1459,40.1472,40.1485,40.1499,40.1512,40.1526,40.1539,40.1553,40.1566,40.158,40.1594,40.1608,40.1622,40.1636,40.165,40.1664,40.1678,40.1692,40.1706,40.1721,40.1735,40.175,40.1764,40.1779,40.1793,40.1808,40.1823,40.1838,40.1853,40.1868,40.1883,40.1898,40.1913,40.1928,40.1943,40.1958,40.1974,40.1989,40.2005,40.202,40.2036,40.2051,40.2067,40.2083,40.2099,40.2115,40.2131,40.2147,40.2163,40.2179,40.2195,40.2211,40.2228,40.2244,40.2261,40.2277,40.2294,40.231,40.2327,40.2344,40.236,40.2377,40.2394,40.2411,40.2428,40.2445,40.2462,40.248,40.2497,40.2514,40.2532,40.2549,40.2567,40.2584,40.2602,40.262,40.2637,40.2655,40.2673,40.2691,40.2709,40.2727,40.2745,40.2763,40.2782,40.28,40.2818,40.2837,40.2855,40.2874,40.2892,40.2911,40.293,40.2948,40.2967,40.2986,40.3005,40.3024,40.3043,40.3062,40.3082,40.3101,40.312,40.314,40.3159,40.3179,40.3198,40.3218,40.3237,40.3257,40.3277,40.3297,40.3317,40.3337,40.3357,40.3377,40.3397,40.3417,40.3437,40.3458,40.3478,40.3499,40.3519,40.354,40.356,40.3581,40.3602,40.3623,40.3644,40.3664,40.3685,40.3707,40.3728,40.3749,40.377,40.3791,40.3813,40.3834,40.3856,40.3877,40.3899,40.392,40.3942,40.3964,40.3986,40.4008,40.403,40.4052,40.4074,40.4096,40.4118,40.414,40.4163,40.4185,40.4208,40.423,40.4253,40.4275,40.4298,40.4321,40.4343,40.4366,40.4389,40.4412,40.4435,40.4458,40.4481,40.4505,40.4528,40.4551,40.4575,40.4598,40.4622,40.4645,40.4669,40.4693,40.4716,40.474,40.4764,40.4788,40.4812,40.4836,40.486,40.4884,40.4909,40.4933,40.4957,40.4982,40.5006,40.5031,40.5055,40.508,40.5105,40.5129,40.5154,40.5179,40.5204,40.5229,40.5254,40.5279,40.5305,40.533,40.5355,40.5381,40.5406,40.5431,40.5457,40.5483,40.5508,40.5534,40.556,40.5586,40.5612,40.5638,40.5664,40.569,40.5716,40.5742,40.5768,40.5795,40.5821,40.5848,40.5874,40.5901,40.5927,40.5954,40.5981,40.6008,40.6035,40.6062,40.6089,40.6116,40.6143,40.617,40.6197,40.6224,40.6252,40.6279,40.6307,40.6334,40.6362,40.6389,40.6417,40.6445,40.6473,40.6501,40.6529,40.6557,40.6585,40.6613,40.6641,40.6669,40.6698,40.6726,40.6755,40.6783,40.6812,40.684,40.6869,40.6898,40.6926,40.6955,40.6984,40.7013,40.7042,40.7071,40.71,40.713,40.7159,40.7188,40.7218,40.7247,40.7277,40.7306,40.7336,40.7366,40.7395,40.7425,40.7455,40.7485,40.7515,40.7545,40.7575,40.7605,40.7636,40.7666,40.7696,40.7727,40.7757,40.7788,40.7818,40.7849,40.788,40.791,40.7941,40.7972,40.8003,40.8034,40.8065,40.8096,40.8128,40.8159,40.819,40.8222,40.8253,40.8285,40.8316,40.8348,40.8379,40.8411,40.8443,40.8475,40.8507,40.8539,40.8571,40.8603,40.8635,40.8667,40.8699,40.8732,40.8764,40.8797,40.8829,40.8862,40.8894,40.8927,40.896,40.8993,40.9026,40.9059,40.9092,40.9125,40.9158,40.9191,40.9224,40.9257,40.9291,40.9324,40.9358,40.9391,40.9425,40.9458,40.9492,40.9526,40.956,40.9594,40.9628,40.9662,40.9696,40.973,40.9764,40.9798,40.9833,40.9867,40.9902,40.9936,40.9971,41.0005,41.004,41.0075,41.0109,41.0144,41.0179,41.0214,41.0249,41.0284,41.0319,41.0355,41.039,41.0425,41.0461,41.0496,41.0532,41.0567,41.0603,41.0639,41.0674,41.071,41.0746,41.0782,41.0818,41.0854,41.089,41.0926,41.0963,41.0999,41.1035,41.1072,41.1108,41.1145,41.1181,41.1218,41.1255,41.1291,41.1328,41.1365,41.1402,41.1439,41.1476,41.1513,41.1551,41.1588,41.1625,41.1663,41.17,41.1738,41.1775,41.1813,41.185,41.1888,41.1926,41.1964,41.2002,41.204,41.2078,41.2116,41.2154,41.2192,41.223,41.2269,41.2307,41.2346,41.2384,41.2423,41.2461,41.25,41.2539,41.2578,41.2617,41.2656,41.2695,41.2734,41.2773,41.2812,41.2851,41.289,41.293,41.2969,41.3009,41.3048,41.3088,41.3127,41.3167,41.3207,41.3247,41.3287,41.3327,41.3367,41.3407,41.3447,41.3487,41.3527,41.3568,41.3608,41.3649,41.3689,41.373,41.377,41.3811,41.3852,41.3892,41.3933,41.3974,41.4015,41.4056,41.4097,41.4138,41.418,41.4221,41.4262,41.4304,41.4345,41.4387,41.4428,41.447,41.4512,41.4553,41.4595,41.4637,41.4679,41.4721,41.4763,41.4805,41.4847,41.489,41.4932,41.4974,41.5017,41.5059,41.5102,41.5144,41.5187,41.523,41.5272,41.5315,41.5358,41.5401,41.5444,41.5487,41.553,41.5574,41.5617,41.566,41.5704,41.5747,41.579,41.5834,41.5878,41.5921,41.5965,41.6009,41.6053,41.6097,41.6141,41.6185,41.6229,41.6273,41.6317,41.6361,41.6406,41.645,41.6495,41.6539,41.6584,41.6628,41.6673,41.6718,41.6763,41.6808,41.6852,41.6898,41.6943,41.6988,41.7033,41.7078,41.7123,41.7169,41.7214,41.726,41.7305,41.7351,41.7396,41.7442,41.7488,41.7534,41.758,41.7626,41.7672,41.7718,41.7764,41.781,41.7856,41.7903,41.7949,41.7995,41.8042,41.8089,41.8135,41.8182,41.8229,41.8275,41.8322,41.8369,41.8416,41.8463,41.851,41.8557,41.8605,41.8652,41.8699,41.8747,41.8794,41.8842,41.8889,41.8937,41.8985,41.9032,41.908,41.9128,41.9176,41.9224,41.9272,41.932,41.9368,41.9417,41.9465,41.9513,41.9562,41.961,41.9659,41.9707,41.9756,41.9805,41.9853,41.9902,41.9951,42.,42.0049,42.0098,42.0147,42.0197,42.0246,42.0295,42.0345,42.0394,42.0444,42.0493,42.0543,42.0592,42.0642,42.0692,42.0742,42.0792,42.0842,42.0892,42.0942,42.0992,42.1042,42.1092,42.1143,42.1193,42.1244,42.1294,42.1345,42.1395,42.1446,42.1497,42.1548,42.1599,42.1649,42.1701,42.1752,42.1803,42.1854,42.1905,42.1956,42.2008,42.2059,42.2111,42.2162,42.2214,42.2265,42.2317,42.2369,42.2421,42.2473,42.2525,42.2577,42.2629,42.2681,42.2733,42.2785,42.2838,42.289,42.2943,42.2995,42.3048,42.31,42.3153,42.3206,42.3258,42.3311,42.3364,42.3417,42.347,42.3523,42.3576,42.363,42.3683,42.3736,42.379,42.3843,42.3897,42.395,42.4004,42.4058,42.4111,42.4165,42.4219,42.4273,42.4327,42.4381,42.4435,42.4489,42.4544,42.4598,42.4652,42.4707,42.4761,42.4816,42.487,42.4925,42.498,42.5034,42.5089,42.5144,42.5199,42.5254,42.5309,42.5364,42.542,42.5475,42.553,42.5586,42.5641,42.5697,42.5752,42.5808,42.5863,42.5919,42.5975,42.6031,42.6087,42.6143,42.6199,42.6255,42.6311,42.6367,42.6423,42.648,42.6536,42.6593,42.6649,42.6706,42.6762,42.6819,42.6876,42.6933,42.699,42.7047,42.7104,42.7161,42.7218,42.7275,42.7332,42.7389,42.7447,42.7504,42.7562,42.7619,42.7677,42.7734,42.7792,42.785,42.7908,42.7966,42.8024,42.8082,42.814,42.8198,42.8256,42.8314,42.8373,42.8431,42.849,42.8548,42.8607,42.8665,42.8724,42.8783,42.8841,42.89,42.8959,42.9018,42.9077,42.9136,42.9195,42.9255,42.9314,42.9373,42.9433,42.9492,42.9552,42.9611,42.9671,42.9731,42.979,42.985,42.991,42.997,43.003,43.009,43.015,43.021,43.0271,43.0331,43.0391,43.0452,43.0512,43.0573,43.0633,43.0694,43.0755,43.0815,43.0876,43.0937,43.0998,43.1059,43.112,43.1181,43.1243,43.1304,43.1365,43.1427,43.1488,43.155,43.1611,43.1673,43.1734,43.1796,43.1858,43.192,43.1982,43.2044,43.2106,43.2168,43.223,43.2292,43.2354,43.2417,43.2479,43.2542,43.2604,43.2667,43.2729,43.2792,43.2855,43.2918,43.2981,43.3044,43.3107,43.317,43.3233,43.3296,43.3359,43.3422,43.3486,43.3549,43.3613,43.3676,43.374,43.3803,43.3867,43.3931,43.3995,43.4059,43.4123,43.4187,43.4251,43.4315,43.4379,43.4443,43.4508,43.4572,43.4637,43.4701,43.4766,43.483,43.4895,43.496,43.5024,43.5089,43.5154,43.5219,43.5284,43.5349,43.5414,43.548,43.5545,43.561,43.5676,43.5741,43.5807,43.5872,43.5938,43.6004,43.6069,43.6135,43.6201,43.6267,43.6333,43.6399,43.6465,43.6531,43.6598,43.6664,43.673,43.6797,43.6863,43.693,43.6996,43.7063,43.713,43.7196,43.7263,43.733,43.7397,43.7464,43.7531,43.7598,43.7666,43.7733,43.78,43.7868,43.7935,43.8003,43.807,43.8138,43.8205,43.8273,43.8341,43.8409,43.8477,43.8545,43.8613,43.8681,43.8749,43.8817,43.8885,43.8954,43.9022,43.9091,43.9159,43.9228,43.9296,43.9365,43.9434,43.9503,43.9572,43.964,43.9709,43.9779,43.9848,43.9917,43.9986,44.0055,44.0125,44.0194,44.0264,44.0333,44.0403,44.0472,44.0542,44.0612,44.0682,44.0752,44.0822,44.0892,44.0962,44.1032,44.1102,44.1172,44.1243,44.1313,44.1384,44.1454,44.1525,44.1595,44.1666,44.1737,44.1807,44.1878,44.1949,44.202,44.2091,44.2162,44.2233,44.2305,44.2376,44.2447,44.2519,44.259,44.2662,44.2733,44.2805,44.2877,44.2948,44.302,44.3092,44.3164,44.3236,44.3308,44.338,44.3452,44.3525,44.3597,44.3669,44.3742,44.3814,44.3887,44.3959,44.4032,44.4105,44.4177,44.425,44.4323,44.4396,44.4469,44.4542,44.4615,44.4689,44.4762,44.4835,44.4909,44.4982,44.5055,44.5129,44.5203,44.5276,44.535,44.5424,44.5498,44.5572,44.5646,44.572,44.5794,44.5868,44.5942,44.6016,44.6091,44.6165,44.624,44.6314,44.6389,44.6463,44.6538,44.6613,44.6688,44.6763,44.6838,44.6913,44.6988,44.7063,44.7138,44.7213,44.7288,44.7364,44.7439,44.7515,44.759,44.7666,44.7741,44.7817,44.7893,44.7969,44.8045,44.8121,44.8197,44.8273,44.8349,44.8425,44.8501,44.8578,44.8654,44.8731,44.8807,44.8884,44.896,44.9037,44.9114,44.919,44.9267,44.9344,44.9421,44.9498,44.9575,44.9652,44.973,44.9807,44.9884,44.9962,45.0039,45.0117,45.0194,45.0272,45.035,45.0427,45.0505,45.0583,45.0661,45.0739,45.0817,45.0895,45.0973,45.1052,45.113,45.1208,45.1287,45.1365,45.1444,45.1522,45.1601,45.168,45.1758,45.1837,45.1916,45.1995,45.2074,45.2153,45.2232,45.2312,45.2391,45.247,45.255,45.2629,45.2709,45.2788,45.2868,45.2947,45.3027,45.3107,45.3187,45.3267,45.3347,45.3427,45.3507,45.3587,45.3667,45.3747,45.3828,45.3908,45.3989,45.4069,45.415,45.423,45.4311,45.4392,45.4473,45.4554,45.4635,45.4716,45.4797,45.4878,45.4959,45.504,45.5121,45.5203,45.5284,45.5366,45.5447,45.5529,45.561,45.5692,45.5774,45.5856,45.5938,45.602,45.6102,45.6184,45.6266,45.6348,45.643,45.6513,45.6595,45.6678,45.676,45.6843,45.6925,45.7008,45.7091,45.7173,45.7256,45.7339,45.7422,45.7505,45.7588,45.7671,45.7755,45.7838,45.7921,45.8005,45.8088,45.8172,45.8255,45.8339,45.8423,45.8506,45.859,45.8674,45.8758,45.8842,45.8926,45.901,45.9094,45.9179,45.9263,45.9347,45.9432,45.9516,45.9601,45.9685,45.977,45.9855,45.9939,46.0024,46.0109,46.0194,46.0279,46.0364,46.0449,46.0535,46.062,46.0705,46.0791,46.0876,46.0962,46.1047,46.1133,46.1218,46.1304,46.139,46.1476,46.1562,46.1648,46.1734,46.182,46.1906,46.1992,46.2078,46.2165,46.2251,46.2338,46.2424,46.2511,46.2597,46.2684,46.2771,46.2858,46.2945,46.3032,46.3118,46.3206,46.3293,46.338,46.3467,46.3554,46.3642,46.3729,46.3817,46.3904,46.3992,46.4079,46.4167,46.4255,46.4343,46.4431,46.4519,46.4607,46.4695,46.4783,46.4871,46.4959,46.5048,46.5136,46.5224,46.5313,46.5402,46.549,46.5579,46.5668,46.5756,46.5845,46.5934,46.6023,46.6112,46.6201,46.629,46.638,46.6469,46.6558,46.6648,46.6737,46.6827,46.6916,46.7006,46.7096,46.7185,46.7275,46.7365,46.7455,46.7545,46.7635,46.7725,46.7815,46.7906,46.7996,46.8086,46.8177,46.8267,46.8358,46.8448,46.8539,46.863,46.872,46.8811,46.8902,46.8993,46.9084,46.9175,46.9266,46.9358,46.9449,46.954,46.9632,46.9723,46.9814,46.9906,46.9998,47.0089,47.0181,47.0273,47.0365,47.0457,47.0549,47.0641,47.0733,47.0825,47.0917,47.1009,47.1102,47.1194,47.1287,47.1379,47.1472,47.1564,47.1657,47.175,47.1843,47.1936,47.2028,47.2121,47.2215,47.2308,47.2401,47.2494,47.2587,47.2681,47.2774,47.2868,47.2961,47.3055,47.3148,47.3242,47.3336,47.343,47.3524,47.3618,47.3712,47.3806,47.39,47.3994,47.4088,47.4183,47.4277,47.4371,47.4466,47.4561,47.4655,47.475,47.4845,47.4939,47.5034,47.5129,47.5224,47.5319,47.5414,47.5509,47.5605,47.57,47.5795,47.5891,47.5986,47.6082,47.6177,47.6273,47.6369,47.6464,47.656,47.6656,47.6752,47.6848,47.6944,47.704,47.7136,47.7233,47.7329,47.7425,47.7522,47.7618,47.7715,47.7811,47.7908,47.8005,47.8101,47.8198,47.8295,47.8392,47.8489,47.8586,47.8683,47.8781,47.8878,47.8975,47.9073,47.917,47.9267,47.9365,47.9463,47.956,47.9658,47.9756,47.9854,47.9952,48.005,48.0148,48.0246,48.0344,48.0442,48.054,48.0639,48.0737,48.0836,48.0934,48.1033,48.1131,48.123,48.1329,48.1428,48.1527,48.1625,48.1724,48.1824,48.1923,48.2022,48.2121,48.222,48.232,48.2419,48.2519,48.2618,48.2718,48.2817,48.2917,48.3017,48.3117,48.3217,48.3317,48.3417,48.3517,48.3617,48.3717,48.3817,48.3918,48.4018,48.4119,48.4219,48.432,48.442,48.4521,48.4622,48.4722,48.4823,48.4924,48.5025,48.5126,48.5227,48.5328,48.543,48.5531,48.5632,48.5734,48.5835,48.5937,48.6038,48.614,48.6242,48.6343,48.6445,48.6547,48.6649,48.6751,48.6853,48.6955,48.7057,48.716,48.7262,48.7364,48.7467,48.7569,48.7672,48.7774,48.7877,48.798,48.8082,48.8185,48.8288,48.8391,48.8494,48.8597,48.87,48.8804,48.8907,48.901,48.9114,48.9217,48.9321,48.9424,48.9528,48.9631,48.9735,48.9839,48.9943,49.0047,49.0151,49.0255,49.0359,49.0463,49.0567,49.0671,49.0776,49.088,49.0985,49.1089,49.1194,49.1298,49.1403,49.1508,49.1613,49.1718,49.1823,49.1928,49.2033,49.2138,49.2243,49.2348,49.2453,49.2559,49.2664,49.277,49.2875,49.2981,49.3086,49.3192,49.3298,49.3404,49.351,49.3616,49.3722,49.3828,49.3934,49.404,49.4146,49.4253,49.4359,49.4466,49.4572,49.4679,49.4785,49.4892,49.4999,49.5105,49.5212,49.5319,49.5426,49.5533,49.564,49.5747,49.5855,49.5962,49.6069,49.6177,49.6284,49.6392,49.6499,49.6607,49.6715,49.6822,49.693,49.7038,49.7146,49.7254,49.7362,49.747,49.7578,49.7687,49.7795,49.7903,49.8012,49.812,49.8229,49.8337,49.8446,49.8555,49.8663,49.8772,49.8881,49.899,49.9099,49.9208,49.9317,49.9427,49.9536,49.9645,49.9755,49.9864,49.9974,50.0083,50.0193,50.0302,50.0412,50.0522,50.0632,50.0742,50.0852,50.0962,50.1072,50.1182,50.1292,50.1402,50.1513,50.1623,50.1734,50.1844,50.1955,50.2065,50.2176,50.2287,50.2398,50.2509,50.262,50.2731,50.2842,50.2953,50.3064,50.3175,50.3286,50.3398,50.3509,50.3621,50.3732,50.3844,50.3955,50.4067,50.4179,50.4291,50.4403,50.4515,50.4627,50.4739,50.4851,50.4963,50.5075,50.5188,50.53,50.5413,50.5525,50.5638,50.575,50.5863,50.5976,50.6088,50.6201,50.6314,50.6427,50.654,50.6653,50.6766,50.688,50.6993,50.7106,50.722,50.7333,50.7447,50.756,50.7674,50.7788,50.7901,50.8015,50.8129,50.8243,50.8357,50.8471,50.8585,50.8699,50.8814,50.8928,50.9042,50.9157,50.9271,50.9386,50.95,50.9615,50.973,50.9844,50.9959,51.0074,51.0189,51.0304,51.0419,51.0534,51.065,51.0765,51.088,51.0996,51.1111,51.1227,51.1342,51.1458,51.1573,51.1689,51.1805,51.1921,51.2037,51.2153,51.2269,51.2385,51.2501,51.2617,51.2733,51.285,51.2966,51.3083,51.3199,51.3316,51.3432,51.3549}

How can I find the first value of the list that is immediately below and closest to 50 (in this case it would be 49.9974?. I tried using closest = SelectFirst[list, # < 50 &] but it seems this does not work with list with numbers in ascending order. I do not want to use Nearest[list, 50] because I also have other list where the closest number to 50 may be the a higher number than 50 (e.g. 50.0001) and I am only interested in the closest number to 50 that is immediately lower than 50 in a list of ascending order.

Thank you!

$\endgroup$
  • 8
    $\begingroup$ Why not Max[Select[list, # < 50 &]]? $\endgroup$ – J. M.'s discontentment May 17 at 3:16
  • $\begingroup$ @J.M. The reason I do not use that is because let's say I have {....49.99999,50,50.0001.....etc} then it will give me 50 rather than 49.99999. Is there any way to exclude the 50 as well as to have the number immediately below and closest to 50? $\endgroup$ – John May 17 at 3:19
  • 7
    $\begingroup$ @John - if you look at the InputForm or FullForm of the result you will see that the 50. is actually 49.99999. Your "Number of digits displayed in output" is set to 6 and 49.99999 displays as 50. $\endgroup$ – Bob Hanlon May 17 at 3:32
  • $\begingroup$ @BobHanlon thank you for the clarification! Then the code works! $\endgroup$ – John May 17 at 3:43
  • $\begingroup$ @John if you had clarified further your question I answered previously, then you could have avoided this question being necessary (this was one part of what I had asked about in your needs for use). That said I will update the code to make this possible and post it here as an answer. :) it’s a combo (in my mind) of Select, Ordering, or Sort. $\endgroup$ – CA Trevillian May 17 at 8:21
2
$\begingroup$

Okay, so, let's see why SelectFirst worked for the greater-than case, and why Max is a better option for the less-than case, especially if we have an unordered list as our input:


lthan = Select[list, # < 50 &];
gthan = Select[list, # > 50 &];
#@lthan & /@ {Max, First, Last}
#@gthan & /@ {Min, First, Last}

(* {49.9974, 40, 49.9974} *)
(* {50.0083, 50.0083, 51.3549} *)

However, the above may not be explanative enough, so, if we wanted to use SelectFirst the list should be ordered in such a way as to allow for this. In your previous question, it was strictly descending, and so we can see the same thing here:


SelectFirst[Reverse@list, # < 50 &]

(* 49.9974 *)

And, the following might be interesting or useful to you:


MinMax /@ GatherBy[list, # < 50 &]

(* {{40, 49.9974}, {50.0083, 51.3549}} *)

Finally, using something like Position, Sort, or Ordering, we could also make an attempt at this procedure for an unordered list...but that is outside of the scope of this QA.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.