如何从Python中读取文件列表?

时间:2017-04-04 16:14:34

标签: python macos algorithm sorting

我必须通过对一堆列表进行排序来比较排序算法,以查看它们的效率(10,100,10000000元素列表等) 我已经实现了算法,直接在代码中列表,但程序运行缓慢,占用了大量资源。 我应该使用什么代码行来为Python 2.7(Mac)从.txt文件中读取列表中的例子?

from timeit import default_timer as timer
import resource
start = timer()
def quickSort(alist):
   quickSortHelper(alist,0,len(alist)-1)

def quickSortHelper(alist,first,last):
   if first<last:

       splitpoint = partition(alist,first,last)

       quickSortHelper(alist,first,splitpoint-1)
       quickSortHelper(alist,splitpoint+1,last)


def partition(alist,first,last):
   pivotvalue = alist[first]

   leftmark = first+1
   rightmark = last

   done = False
   while not done:

       while leftmark <= rightmark and alist[leftmark] <= pivotvalue:
           leftmark = leftmark + 1

       while alist[rightmark] >= pivotvalue and rightmark >= leftmark:
           rightmark = rightmark -1

       if rightmark < leftmark:
           done = True
       else:
           temp = alist[leftmark]
           alist[leftmark] = alist[rightmark]
           alist[rightmark] = temp

   temp = alist[first]
   alist[first] = alist[rightmark]
   alist[rightmark] = temp


   return rightmark

alist = [3706,798,72,4014,4211,4054,2068,868,1537,4421,535,3099,4290,74,4898,848,3661,4969,2860,3524,364,2437,1067,2933,739,1968,952,3491,2219,3408,4590,623,4876,686,4140,1280,2597,2297,3538,1662,655,1291,2708,1561,3727,4292,2697,4524,3532,1749,4778,2852,4274,4331,1606,2096,3965,1493,1155,2074,3356,4249,841,2700,857,523,1564,3682,2443,118,3876,315,95,520,3025,3207,2659,1396,4139,3646,2705,4817,502,303,1395,4692,7,4095,3555,589,712,4931,1813,896,379,4447,3095,2965,3862,1068,1630,3259,2905,548,3928,1000,4242,3201,568,3778,130,3687,1362,3537,4275,3485,3793,1064,2539,2365,688,3387,1581,1059,917,4726,3653,1283,4715,1292,1855,1985,1157,3641,4957,902,3267,1932,2908,4027,79,4937,1105,4950,4974,4491,833,541,1410,2559,3967,2147,1365,3252,244,4904,3398,570,3761,2652,4913,2609,3710,4474,345,1178,2685,3279,704,93,1161,4882,4956,3413,1142,3404,3639,2691,4935,637,4127,4756,2453,3613,2840,3425,4934,2328,2073,1588,3059,4700,1964,1665,2043,3013,3161,4766,4221,2349,3283,2336,560,4182,2050,2211,1664,3220,1099,3964,3553,2800,533,1541,719,60,3523,4379,276,3411,3645,3947,1812,2299,2952,3889,3589,3779,3003,4795,3620,3747,3266,3993,321,2944,4469,4589,1156,3191,4266,4788,1466,3064,3635,2041,3026,1430,1227,3464,4895,4684,4825,1592,4372,4047,606,3004,3107,3475,1667,4020,4043,741,4457,3514,2244,81,1512,1656,2148,3568,4887,1302,4287,1449,2875,1372,1367,172,1113,4885,4513,1172,516,4801,4819,4842,2733,1019,4006,3264,1260,2371,4335,4230,1705,2706,68,4371,295,3065,4277,1567,376,1888,3451,1401,4522,4180,3193,16,3394,4697,755,3519,1247,2566,3675,1757,1984,1739,1199,4068,113,4543,4897,4994,1154,401,2013,2383,3102,3546,2534,4409,720,617,564,21,49,4284,365,1134,1595,2780,1004,3985,843,2730,3452,4879,814,4041,2265,3301,2518,2026,2616,4633,4780,3209,1653,3848,3165,2806,4709,163,1797,803,2738,449,3877,522,1145,2951,4688,3034,2276,1177,105,3664,3441,2693,4808,3032,1296,3471,2945,508,3908,3361,2514,3160,937,1028,4706,3050,2865,3878,2032,1650,4056,305,214,667,675,2151,1187,2819,3835,721,3995,2638,621,64,1916,4241,1282,4807,1129,1963,4888,186,3449,3745,2195,1462,123,1668,3836,2613,1773,4587,3720,2779,1327,4653,203,2375,4583,3662,3931,3305,2405,2724,421,4660,368,1854,3498,2242,2927,3558,4774,3385,840,3455,3027,1893,3300,1477,3103,142,4489,4057,4676,4947,342,4282,486,2199,3474,685,923,2326,4343,4635,4197,147,1352,1472,4425,2874,3180,4133,4179,2477,4977,3804,2761,201,4541,2062,3228,4102,2455,39,4796,4044,2750,3863,961,3380,543,230,3780,820,3972,3760,3359,2784,3859,1598,2379,3078,3607,1629,3533,2977,3208,722,4115,1264,3158,4926,687,3671,4663,1524,3510,2658,3035,3097,54,1768,4105,2100,4909,3092,3495,1814,143,1464,2196,612,2105,3339,3624,1431,4976,3288,2618,1043,4659,1502,1826,284,2246,3843,4053,3219,3757,2156,1796,2912,3336,2815,2773,713,2478,819,2426,4979,659,1479,3936,2231,1261,3502,374,2859,534,2083,513,4414,132,3509,2064,792,2178,2284,2311,391,1116,2890,1691,432,4544,610,4683,4922,3730,1066,4195,1550,1863,4382,914,3823,1807,544,2469,3431,1014,3698,4722,1546,3581,4767,2063,1204,4456,4839,4280,3080,2595,2399,569,681,1037,965,249,2581,3187,4389,1152,826,4268,297,388,2395,3999,122,949,983,1503,1583,1110,443,1686,3104,2542,4129,2972,2332,430,1523,3754,1436,1170,3001,2866,4304,3454,1409,361,2424,3875,3790,2861,2367,4824,3439,2803,4712,2877,1299,3270,2204,3330,2325,2422,25,1140,2139,4899,1649,2419,1255,3856,332,2102,288,3194,4728,1056,3084,1297,3240,2886,4820,810,4655,996,3803,4310,355,2605,1159,367,2345,1637,3287,2260,1886,2894,4570,2238,4868,4613,4594,4597,1514,2263,3705,35,627,2267,3637,3579,2678,406,91,2291,870,3565,918,3905,4721,2759,3149,1604,399,2256,4612,1731,208,3048,340,112,3349,3077,4301,2849,3785,772,2743,3016,2603,1057,4405,2167,873,3306,4086,3186,2384,1311,4921,4471,1316,1684,3741,2610,4323,3975,107,3526,4638,974,2241,120,4675,451,4046,4123,2999,1389,3784,3135,1048,1265,3293,4224,4397,2882,644,1987,930,3858,3304,1622,4690,3337,3891,3640,2793,258,4151,3894,219,3121,4611,4136,2629,2673,4347,4207,4166,2269,2002,1476,260,4296,1972,395,2087,1070,4294,707,4733,4575,2157,1725,2160,1378,3833,2931,400,2867,4762,1024,2787,2642,2122,851,2778,4077,1551,3461,3237,4422,942,1385,1983,126,2277,679,1063,939,3348,335,1917,2682,4850,119,1440,3146,146,4894,1840,4449,2587,3210,4734,3019,3312,1267,3008,215,1743,2040,3298,2142,2640,763,134,4566,1729,630,3841,1287,2740,4428,515,2171,2140,3527,408,2997,4216,850,124,2942,3826,2567,1439,1230,56,1836,1915,4689,3658,1390,441,3282,1345,2090,2825,933,4350,2723,4530,963,3224,3962,1330,328,3364,1374,3742,353,759,3657,2835,4356,968,1999,2767,4237,3809,61,3674,2719,4968,4578,195,2407,1485,4656,3821,4713,1369,1680,1641,2228,3772,4599,4844,3567,4650,882,3737,3953,636,1079,4579,4363,2282,3419,2964,2440,2441,3771,4482,2112,427,125,892,3776,2057,1016,1457,3969,4074,1671,1675,460,4636,3325,1101,1402,943,4373,4695,4295,2911,3253,1872,4028,1864,2381,2236,2856,3024,88,1727,2320,3120,2969,2521,3140,3274,3663,4271,715,767,4432,3588,3038,4106,649,794,1801,2357,3216,682,4206,725,3874,1359,190,1109,1879,151,562,41,699,1183,2929,1902,183,2448,887,2904,4476,1549,1694,181,4830,2302,3465,4316,4417,671,1349,1164,912,3262,1081,4812,976,2028,4517,2389,4532,5,1570,4019,638,85,1508,525,3432,139,618,4915,191,200,2712,3976,1238,4376,3847,1817,1488,1226,3951,1654,2056,3906,323,1540,1980,2533,1951,2505,4787,3958,2194,3991,845,2285,4845,4492,2813,3606,459,1744,116,2811,981,1767,1685,760,500,4259,3550,2312,4333,1383,1455,1896,46,416,2397,4610,4551,77,4982,915,2391,884,1748,2044,2492,3660,3143,4764,2564,4618,4598,1979,2104,4185,4385,1295,537,1562,4668,2425,3074,3937,2429,385,3883,2897,728,1450,1789,4436,1648,3374,1192,1253,240,1769,4283,4843,4091,985,429,221,174,2012,2278,762,4998,4446,66,4664,4269,490,4080,314,1692,252,4108,1695,3373,990,4118,3372,1304,2120,1214,1871,1406,263,301,2022,3866,4387,3938,4451,1408,3022,2475,4528,1875,4087,4948,4448,4340,1760,4687,1348,4581,4955,3473,1318,4445,2742,1865,3709,3009,1538,4988,2873,4862,652,2932,724,1953,927,4869,1572,3692,2258,2078,1118,2720,2463,390,3457,3791,3763,1793,1381,4569,2634,247,2271,594,2826,3732,2643,115,2220,2589,991,2657,204,2103,1151,129,4643,3633,2960,690,2660,2420,1940,743,1245,4983,4646,3501,1975,1713,1090,4159,2785,4685,4574,1534,3506,2432,1706,605,729,4245,2303,304,3132,3786,1851,3271,1956,3049,3222,3405,4390,450,575,210,3997,1802,2019,231,3799,602,1753,3280,4873,1289,1216,1530,1574,2508,169,579,818,2575,3694,3864,2086,1397,234,1317,3913,292,2751,4114,2607,239,2070,633,514,4526,4169,4940,4200,2827,4752,1919,4442,372,3957,1190,1188,4470,1557,356,4052,4107,3277,1646,3479,3289,2206,1922,4938,3214,4176,1241,2653,4285,1321,4515,414,3409,4401,521,3596,3128,2881,1615,3616,3486,344,4946,1334,1882,2524,202,2855,2212,2449,485,1586,1584,1058,194,1347,1651,4051,3896,2843,4434,1469,4300,3748,4724,1998,2504,1269,4508,4642,1948,3542,2872,3842,4060,1736,4797,4320,3560,1141,3338,2249,2725,2135,3332,4485,4833,3156,3593,1373,1098,3164,193,4971,4062,807,526,2531,2268,3412,3887,959,4112,4870,1884,823,2473,1423,4910,34,1315,1905,1368,536,3812,2342,2675,250,2837,4586,3978,4214,366,2764,885,4111,1375,262,2621,4393,1766,2921,2169,3088,152,1467,223,4229,777,4939,392,3418,4703,2919,3082,2499,1644,3611,2308,4210,3499,1990,4324,596,4078,1824,4837,1827,2164,3946,153,4674,3437,2232,2468,3141,3880,3595,1339,1696,2218,2307,3669,4967,3415,2598,254,4113,458,3728,4330,4473,1089,3206,3260,3053,2798,2293,3755,1340,3861,287,4572,3118,883,4552,3133,1577,4627,557,1735,804,2235,363,1071,989,1971,4092,3764,1471,3134,405,2880,2243,1939,2889,580,2554,4875,2878,897,2976,3777,4250,4462,1223,4120,3515,3505,3382,3810,1337,563,874,889,1314,4811,4016,3037,1628,3697,4321,1640,780,3181,2899,4252,108,4616,2450,955,13,4050,3303,4399,4993,2502,4741,2714,2200,52,4302,853,1143,1909,469,2247,545,4235,1822,2237,2202,2515,813,3215,4719,347,2506,3169,4919,778,350,3981,1711,1560,567,264,629,2868,3629,4806,806,530,3276,4199,2814,4494,2130,3627,929,3689,1690,3758,2646,3113,2077,2333,4171,1407,1254,2451,1193,4785,3818,4218,542,3235,4475,3959,2582,864,2545,2314,651,3229,3984,4732,1364,1144,1808,3547,3685,4647,3759,4677,549,4411,1874,2936,512,4034,1794,4826,184,1619,4945,4152,307,2711,1507,2330,4013,4309,4930,3184,3924,4443,4648,3949,4986,44,2485,1338,815,2408,1125,944,311,2641,2047,2360,4384,2150,84,4349,4883,1025,162,1995,2025,2240,1388,2467,1988,1603,1062,59,3762,1358,446,2628,1459,3217,588,2617,4972,1228,4662,3089,613,4731,3925,453,1158,1235,1354,1162,4827,4718,956,1941,2769,1519,412,4130,3554,3031,1712,3255,213,791,2175,4126,795,572,3775,3559,3101,3811,4871,1262,4312,1011,470,4454,598,3200,1167,4005,3516,4201,616,133,908,734,964,2081,1683,10,1120,1446,1526,1480,3211,4465,3507,1600,3648,413,3573,1831,2670,2098,3192,404,4989,4083,3231,1958,4644,735,747,2516,410,206,736,697,3831,4143,2127,4012,104,2735,2715,3392,631,2847,2374,1003,2462,4645,4531,2854,1166,1460,2080,828,1510,2757,4015,2863,3703,4009,1232,3926,1443,3456,487,3223,742,278,2590,634,1310,980,4035,1107,1212,1153,1351,1400,1434,4234,2491,3541,2655,2548,3233,3487,4267,4565,693,2460,4603,3713,1772,3695,2480,2216,43,2783,4588,2119,1605,2786,1293,2870,1677,875,2343,624,3257,2182,4745,4851,3849,574,271,4729,4738,2255,2210,1925,1044,1132,3756,2145,1205,4191,3796,950,558,1788,4138,1533,1823,90,1041,3130,3738,1780,4149,136,3040,2351,3517,2304,2966,2144,599,1698,1392,4717,4629,2378,822,4272,409,1268,4523,1991,2033,3600,1074,4190,407,1032,1220,1035,1618,2994,2721,1290,1710,1257,4846,797,4255,4652,4679,538,192,2409,640,1108,3968,4004,765,2909,117,4369,3286,1721,3699,3091,3583,2359,4857,1185,3468,189,4622,977,2361,3723,3152,4366,3966,3227,4497,291,3307,2234,3512,177,2771,770,377,1438,650,2034,859,319,1751,298,676,661,4654,1610,1531,4502,17,3739,1495,4262,1219,2584,4243,3982,4798,4175,1912,1830,205,827,362,3397,2957,635,2884,2124,180,2427,4479,12,1899,2986,3400,607,550,3551,1900,3767,3367,2817,4999,3700,1904,3302,1726,1513,3980,2245,3563,38,3850,2385,4832,1065,3768,2123,3069,3427,546,1950,4413,1453,2296,3174,2920,1197,493,4790,674,4864,895,4754,830,2217,3115,3615,1883,3012,2903,480,3933,3218,476,2689,1114,2143,1881,3294,4809,962,3317,4769,3401,1943,3406,1463,415,4460,2000,1184,2257,4468,3292,2925,565,2782,3676,1617,2550,4896,3820,1246,1702,796,1,294,3691,2570,2990,2430,1579,2313,4529,1908,1829,101,1517,3171,1413,3805,2774,3903,148,1658,4002,1270,1897,2982,2749,2893,2848,4370,4441,464,2193,4018,4714,289,76,3393,2158,4378,2853,2368,2732,2667,860,3046,2937,154,282,3242,448,384,2791,844,2305,4874,4412,3591,2955,3631,3363,4933,595,2651,3482,1433,4906,4466,4488,3656,2522,3898,3806,4822,235,1981,3765,1708,4406,4881,259,1312,4359,3792,4227,4776,2006,199,4753,167,3683,3116,4859,3721,4357,1946,2133,1093,1597,1722,4374,3970,1745,1332,3062,2901,109,320,2718,462,982,2327,1189,4601,711,1655,437,2948,2141,879,1848,3807,2576,3434,2295,4203,4486,4101,708,4941,3578,2709,3407,1484,2454,4098,2671,4516,3577,3041,1857,2561,1045,2970,2596,3073,2089,2978,3556,3649,2051,910,2472,3308,609,744,3528,4026,2495,1370,1670,4156,978,4440,211,2459,4278,3402,3839,4222,2045,1202,216,1139,2807,2114,1399,1632,1336,4400,4932,3199,856,274,751,1012,3822,2279,3684,969,4952,4984,175,2481,3014,1078,2362,2423,1218,4032,1498,527,876,75,279,1288,2215,785,182,1417,3612,3,3093,2176,906,2540,2729,3238,2591,227,2507,1243,4880,4307,3265,3690,1764,158,1850,1097,4031,1962,1276,3815,1279,509,3677,121,3177,3909,4860,4334,2009,402,4030,4001,553,4256,3566,3884,3598,771,4949,222,2187,2486,503,2380,2808,2222,539,3696,1661,1023,4314,1191,899,1432,2726,4963,4424,1728,1635,1576,2851,835,3081,1818,2208,4829,2445,1133,4258,1620,1591,746,696,811,4743,1294,2838,1548,1821,2805,3668,3608,3638,157,2011,1609,2465,3625,2914,511,2071,3571,436,4911,3362,3144,4104,4916,2810,2568,2971,3029,2544,593,4783,3197,1699,2906,727,1930,1555,3789,4490,2132,3275,1233,3142,4172,1997,1483,1554,4438,3882,2274,3072,1974,591,349,3290,816,2585,4973,2340,99,4920,1500,1724,1734,3284,880,945,1128,3182,3890,2962,2076,325,3650,2387,2400,4710,2337,4125,2688,2674,3042,2547,1977,2190,710,2973,4196,4326,601,4240,787,4163,1742,3086,4189,3322,4360,1456,783,3521,2109,2702,730,966,1303,4510,1967,4315,2788,1277,224,2698,1862,1181,1701,1387,3269,1895,70,4208,1053,1805,2722,836,3989,2203,2390,4157,2116,1088,1174,468,2259,1634,4147,4607,664,2300,2010,4362,1613,1786,1552,1779,1511,1281,2166,3341,4847,3360,3851,3701,1442,466,3934,1300,838,2556,4802,4075,1535,519,3773,2926,3410,2987,886,4236,2588,2412,3592,1331,2382,2736,225,1326,1215,4828,3557,4794,3469,1545,4755,1494,296,3430,96,3746,1341,3122,1272,1518,1006,145,1424,931,489,3319,2031,1452,3733,1785,4604,4415,4122,547,2138,4701,2358,3285,3472,4204,4504,3834,4639,2833,1342,4964,2857,3005,57,1709,4585,1135,1085,2456,1209,2396,3920,3597,677,1838,3021,4838,998,3315,166,2850,871,1092,3954,417,2520,2910,4251,775,4996,380,1982,4678,3250,3342,4367,773,3100,1947,2662,439,4444,267,2946,3960,3202,3347,4388,3520,4205,1020,2530,3075,1568,2528,4084,3154,2979,3688,1130,1733,597,4354,4427,941,1239,4407,2161,3902,2185,4017,4153,3334,3892,4263,2573,2690,4289,4985,431,3659,4742,3712,995,2372,957,1626,4132,4336,2201,255,3797,3011,3299,2823,1645,473,78,3232,576,53,1131,4076,2115,4634,3910,4260,4459,4961,1418,3085,4640,2538,878,3722,3488,2541,3023,4518,1026,4146,1015,2092,1124,4352,2635,839,1892,1102,3979,33,4666,4228,1333,4431,1732,1123,1852,4298,4560,4878,2818,3496,1505,4183,788,1234,701,1054,2592,329,4472,2746,894,4364,643,2692,3644,3079,3816,2363,1806,4905,2604,1945,666,1137,2758,4481,3417,137,424,4177,3145,2226,2900,4137,4557,341,3942,2482,2394,2042,4693,761,3719,3204,2829,1740,141,4144,3010,2005,1911,4419,3155,4317,2418,2431,4944,1492,2975,4499,846,2162,1715,4760,2017,3632,4213,926,3983,1657,665,1050,4609,3039,2224,2796,2205,2922,4154,1481,275,1558,2055,2192,333,442,2155,389,381,2608,3971,28,3725,1849,3055,1986,2319,1096,3529,3058,1324,784,1697,3950,4900,1163,1119,2496,559,393,4164,2198,3247,3603,971,1386,1566,1960,2992,63,270,1411,1491,3066,3105,4048,3871,1252,4548,1703,1556,94,69,2665,4791,1923,3602,4194,3263,782,4341,2364,3226,801,3654,1100,2154,3421,3090,1787,1542,471,1770,1949,4981,2289,2684,1761,463,1765,2344,3681,4297,455,692,2209,1451,852,269,953,3071,3369,4093,4099,3268,4003,737,4858,4959,2183,3868,433,4631,2896,482,4608,1660,4671,1601,566,2526,2129,4558,3416,702,481,1080,2126,3830,283,2350,246,4022,461,1906,411,3112,2179,185,3824,1716,1778,4029,40,1366,1404,4632,4696,603,2654,1759,3188,2338,272,2812,4902,496,970,4577,2869,3354,3151,709,1475,4739,2763,3044,357,4606,1573,4437,716,2583,1920,3729,4966,4254,2938,2680,398,3813,1231,14,4498,831,1521,1903,3036,3057,11,2820,768,2294,1478,4914,4620,268,3665,4455,800,131,339,1679,2146,2917,483,3442,426,4365,4110,3483,422,3313,382,3438,1104,2645,2656,3153,1415,1880,3236,821,1445,265,3445,4141,465,1996,4346,26,1966,2794,3594,672,979,2981,2940,2710,3544,285,229,4010,3117,3904,4997,2694,155,447,738,3708,1820,4903,805,3941,2137,2052,619,317,2170,4615,4081,504,4396,766,1405,3162,4750,3623,3963,4109,1394,2562,3123,1082,4669,854,4672,867,3051,2623,4836,2393,4975,662,1730,1804,2755,4571,4327,1298,2781,600,2795,2097,4582,2995,556,2254,3854,3769,829,2464,4800,2560,3414,20,4525,1426,4420,4698,975,752,499,3189,4308,2766,299,3724,3766,3195,4217,916,4550,334,4657,1149,2633,2008,2290,188,3168,3462,583,67,3185,1087,3917,3888,3351,646,4840,2386,2428,1175,2301,2594,872,3504,4322,3494,2021,764,207,1379,4803,418,3205,3119,3068,3190,2039,4193,832,3955,354,1343,4702,73,2356,4534,555,3254,1021,4439,3291,4410,3534,2703,2316,2614,1841,1429,2887,972,3513,3329,87,1959,4923,1928,1860,3251,3106,703,3321,1616,1284,789,1976,1049,3310,4927,2943,4065,3125,2775,1473,4351,3395,3881,3893,1845,625,4736,492,4487,1627,2716,327,2001,3543,3539,2438,3530,2792,1798,4556,4483,1160,4512,2069,3994,3783,4793,4852,2983,3157,1422,4353,3375,111,3774,2676,2707,2537,55,507,808,351,2615,3914,745,4000,4038,2552,1060,2650,2503,3734,1126,4265,3912,817,684,2954,3166,732,1474,888,1528,4375,3819,3707,657,1186,4621,893,2527,4033,3929,1022,3585,3326,82,1931,4848,4329,678,4239,726,4535,3477,226,346,286,4960,2347,524,4834,967,360,2149,1970,2752,1206,3355,1859,1237,1061,4273,1847,2233,4576,2444,1052,3083,1969,1249,4605,50,1775,1935,4563,3176,1489,5000,3110,256,1251,3466,4691,3340,2334,4215,1539,776,403,2883,242,4131,3448,3531,3897,2072,3020,4073,1201,2934,1182,2501,3562,3246,1069,4978,4288,237,1781,2968,3846,2369,127,2180,4789,2239,2168,2789,1752,4619,6,2572,2753,2696,1346,3436,2131,1544,3344,4553,2532,948,1559,1454,2309,4072,578,4089,1027,2457,4394,1072,3248,4299,3666,2776,2058,4779,2046,2845,4119,3381,3916,2197,4987,517,4567,2630,3610,1532,1666,3873,2406,2599,2892,1380,4429,3000,2186,809,1420,3680,919,1754,907,2731,2272,4818,4174,2644,1784,1115,440,3309,3770,3136,4279,3198,3832,1755,4821,3030,1520,3450,233,2511,506,2248,232,103,2557,1112,4358,2756,338,4514,1707,2283,940,2354,2266,4925,1138,472,936,3744,4723,824,4991,3422,3990,2830,3817,1688,3493,2331,1200,3617,622,1305,3702,1763,862,1934,3396,4345,3549,863,3213,3297,1792,497,1907,3147,2093,3331,2888,3795,1819,3569,1360,310,434,1790,934,2288,3328,1927,2264,1207,2844,2352,4980,1051,4303,369,1693,313,4049,658,1624,3063,337,198,3622,2207,4649,4617,4547,359,4954,1936,4496,1590,3749,2601,4395,9,4562,4841,2510,4145,1329,2159,2497,1007,3480,3129,2822,4748,1486,4500,4624,4761,1095,445,3261,4593,2177,1835,1536,4059,475,245,1607,1221,4527,4699,505,2189,4202,3855,3111,100,3825,1363,2898,2442,2980,4311,3098,3002,866,3860,3500,3353,2963,3054,2095,3584,1774,786,1718,4402,97,3718,1993,3047,3872,935,2770,3295,2322,1867,3576,1795,2930,1816,2991,2067,2091,2509,4763,4253,585,3753,2672,700,3711,3552,2871,241,3241,1638,3272,3052,573,1783,4264,144,3647,45,994,218,2546,3829,1843,29,2663,842,2355,901,3490,673,1127,22,1669,920,999,4381,3735,1747,1689,2619,3798,4918,3170,3453,2602,3827,1833,2329,161,3886,3124,479,4799,3256,1076,4889,3605,4082,4890,248,3961,3388,2376,2273,47,620,960,2108,3221,1030,1522,1278,2846,3717,1256,2229,4682,2458,3391,228,1525,1776,2578,4670,2061,1211,3196,2842,1259,4705,477,3572,1468,2029,4165,4398,312,1602,4168,3570,4782,3996,62,3935,4538,754,1444,4625,3138,1885,750,3974,3643,4186,4770,2227,3918,2118,2704,3318,4342,2577,2745,80,1585,1937,36,2949,3714,1210,1490,4276,293,584,2748,4637,452,1889,2003,4090,2498,4503,3056,4665,4555,733,32,1412,1353,891,2466,4744,4478,2523,925,1176,3503,3426,3368,2488,3376,196,855,3366,4036,2895,3801,3447,2476,3109,1553,3371,4337,2261,495,2452,3399,3278,498,165,2136,2181,2317,1391,3383,604,1756,173,3574,2035,4212,3428,1876,4917,2346,4192,419,1213,2401,2728,2620,31,3033,322,4865,4965,2339,3678,4325,2961,2082,348,3901,2436,2373,2262,1361,243,2038,1008,2023,1322,1482,1750,4877,128,3609,3540,4564,904,932,4128,3350,2230,3977,3094,3927,396,3940,2593,1869,1009,2094,774,420,2,2121,731,4784,3365,1217,1121,2484,3973,1470,2804,4614,4162,3636,3802,168,3879,3655,4943,4121,1529,4332,2668,1593,1017,1672,2128,753,1961,3907,488,2517,2489,2834,383,1047,2864,3458,1371,2184,1954,2280,2306,2281,4495,1010,4142,2569,1274,2411,3377,3525,3357,474,1901,3273,4318,1978,140,4813,106,1229,2832,273,518,898,4477,4039,1122,4116,4708,4765,1563,680,4658,23,2998,2223,3296,1887,2270,4891,1791,1309,454,2571,3794,1286,4209,3575,1633,3915,2727,4188,1914,3390,984,306,2636,2739,4167,4861,3686,1611,2439,3386,3992,4040,4392,2366,3752,4435,1001,4386,1086,1225,3923,1437,1643,3670,947,714,2474,280,4573,3335,2799,1614,1039,3314,3429,1973,2535,352,645,4416,3787,3481,4651,3203,3244,2341,1083,4628,1275,2101,4198,1682,160,1504,425,324,375,3150,2030,4596,2433,642,110,4623,435,3484,2801,2958,3446,1465,3743,1594,1587,3535,1652,1046,1103,909,2768,467,3087,4511,3651,3740,2612,3800,98,3017,1870,946,4720,2250,4509,4507,102,2664,3518,2253,3536,4735,3281,2824,632,1029,3175,4907,861,3127,654,4901,2802,4404,2493,4602,4480,4600,2637,3139,2404,456,1910,2461,4545,1328,529,1313,2252,4884,2054,378,2993,24,3614,3619,3470,3258,4024,2172,1263,4286,3327,825,2626,3324,1815,1169,3604,4992,4011,1196,1828,83,2797,1631,3459,656,438,1487,1723,2661,4008,3460,2213,4025,4181,3814,4835,3750,1547,1674,2004,2221,1844,1136,150,812,1242,4117,4380,3028,958,27,2435,4007,1738,3163,3948,2988,1720,4069,1965,3320,2543,3463,2152,1994,834,3183,4403,3952,1921,164,1700,2113,4423,1894,89,336,2625,2292,3867,1150,1933,1580,3704,1704,358,4855,4281,2631,2967,3618,4520,1447,1208,1509,1273,1461,2500,2027,1926,2876,1356,3018,2037,4773,3179,2956,4716,281,4872,217,1094,2558,2687,1878,2173,1846,1306,4863,4775,4751,2772,3857,1425,3249,2310,2529,4463,2049,3467,592,2939,2048,4173,2754,2555,2191,2734,3346,2686,1571,397,326,2106,4058,552,1642,330,641,4540,212,1717,2563,2923,1040,2790,586,2536,1873,2699,4391,2632,4768,3172,3131,532,992,2066,4418,3108,1866,2777,3587,1075,1898,1673,2744,1013,3895,1924,423,1034,1428,316,1599,1195,2434,1623,4816,2298,3378,1687,3384,71,238,4383,1168,3736,1325,343,2928,2831,3865,2695,4248,1350,951,1384,4929,1890,1569,540,3845,561,1448,4792,1832,4908,171,3478,3601,2388,3944,740,3945,2579,4568,37,457,1944,1344,4549,3808,769,2985,1355,1258,3634,1676,3045,3333,4231,4377,1842,2713,3015,2879,3561,4124,4554,3726,2953,3956,922,3060,4219,3599,4951,4484,3885,1323,3043,865,2974,371,4912,2487,3899,4970,2323,3311,1942,4270,1499,2947,2174,4694,3781,4995,2110,756,4561,1308,4408,877,2470,3853,2125,4450,197,3173,3167,156,4094,3626,4536,2324,1250,1414,4630,3234,4591,1427,718,2084,4097,2611,386,4021,3930,4853,2286,236,2681,266,986,4070,531,4467,4953,4328,4135,3420,4344,849,2015,58,3652,4704,4088,4758,4339,881,2519,1180,176,723,4519,3403,2016,4772,938,1578,2353,3489,3159,1416,4433,4458,3006,179,2580,1307,1419,2447,3548,4810,757,428,4291,1393,2117,2606,4067,4225,4037,2287,4042,2885,4293,4707,1719,373,2414,3379,781,587,1839,277,4595,4306,1091,900,135,2737,2935,4805,4079,2862,2490,2413,2669,4924,1005,4257,2989,1737,903,4100,3433,3212,2415,1179,4085,748,86,1853,2600,1877,648,1938,749,2924,1458,2760,2134,30,1516,3564,2079,331,2549,4746,370,4023,2421,2479,2574,3444,4777,2059,1506,4464,2762,2836,614,2679,3424,4150,3070,2916,3239,4064,2513,3114,4338,3007,2471,1194,1496,444,1527,1837,2959,698,1335,4220,3673,1301,2984,988,987,2747,1285,4942,4233,1803,4936,669,1441,581,2321,510,3922,18,2085,4452,3225,1955,4313,4247,4681,1810,2065,2099,1809,717,1811,2622,1565,2024,3852,2913,3911,4223,4786,1244,2446,1799,3693,1036,3672,1891,3178,484,1621,1198,1957,3586,494,2188,3492,4,387,2165,2416,2107,1236,993,1106,2841,1913,2163,4430,847,4161,4261,1271,3508,290,4584,3921,1678,4686,663,2392,3243,3497,4867,660,3630,528,3316,1659,1042,2907,2075,209,4226,3642,2402,4319,2717,8,149,3358,4103,2225,4096,590,3943,4187,3343,1612,683,3440,4823,1240,4063,3840,1800,4667,1002,4071,2624,3837,1834,4066,4580,2036,837,3751,3443,2018,3423,921,3580,2666,3522,1575,4990,1825,4849,4148,890,4045,3939,793,2902,3986,170,159,3988,4521,1918,3352,1320,3545,628,4158,1421,4928,577,3582,582,2014,554,913,2950,1663,4232,4426,3389,3919,3590,3828,3148,3230,42,1033,1589,1515,1248,3932,1077,48,4134,3511,928,2020,2858,1501,4505,1382,1782,65,2060,1989,2821,997,1714,4854,1222,4155,4178,2275,694,3067,2088,2648,220,3731,257,251,4680,802,790,1084,1596,691,4055,695,2565,4542,1403,2586,905,2214,4348,4493,15,253,4958,3628,1625,138,1435,1147,670,799,4893,4537,3987,2941,1777,2551,3476,1173,2153,2512,4892,1647,309,858,4737,4641,1146,1148,4730,1398,4546,1203,4804,261,2918,2701,4592,394,2417,1582,2647,1771,2839,4711,4673,4771,911,3715,187,4533,608,1117,1165,3788,4814,2639,779,4461,4740,1636,1639,2370,615,308,706,1031,1858,954,2377,2553,3345,114,4501,4244,3323,551,3782,1377,2816,2649,1111,1073,1224,4160,1741,647,2251,4866,3844,4727,4170,2398,2335,1018,2111,758,1357,4759,2494,3870,4856,3245,1952,4539,3900,19,1758,611,501,2809,4626,1038,3076,973,1376,1856,2403,2915,4368,3869,1762,2053,3137,4886,653,3435,4781,3126,924,4184,4305,3370,4725,4757,668,2348,302,1543,178,2315,2627,4831,2683,478,4361,1497,2410,4815,3061,2891,4962,1868,639,3679,4238,92,1746,300,2525,4506,1319,1681,1929,1171,4559,2007,2483,1608,2741,3838,491,2996,705,2828,4355,1055,4661,3621,689,3998,2765,2318,3096,1992,1861,4453,626,869,4246,4749,2677,4747,571,3716,318,4061,1266,3667,51]
quickSort(alist)
print(alist), resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1000
end = timer()
print(end - start)

由于

4 个答案:

答案 0 :(得分:0)

对于你想要的东西,这是一个很长的问题。我认为这个问题的答案大部分都是

How do I execute a string containing Python code in Python?

基本上,要将其转换为列表,您需要使用

with open(fname) as f:
    content = f.read()

当然,如果你想从文本文件中读取字符串,那么这将回答它

Flight.where(arrival_date_time: "2017-04-02 23:29:43".to_datetime)

答案 1 :(得分:0)

文件对象在Python中是可迭代的,因此如果您有一个文件,每个数字在一个单独的行上,您只需打开该文件,将其视为字符串列表并将每个列表元素映射到整数:

with open(filename) as f:
    alist = map(int, f)

答案 2 :(得分:0)

您可以在没有括号的情况下将列表保存到文件中,然后使用numpy

import numpy as np
my_array = np.genfromtext('filename.txt', delimiter=',')
# this is numpy array, to convert it to list do:
my_list = my_array.tolist()

或没有numpy:

f = file.open('filename.txt', 'r')
long_string = f.readline()
my_list = long_string.split(',')

答案 3 :(得分:0)

您始终可以以pickle格式保存列表并批量检索。 这个link会对您有所帮助。

这是一个例子,

import pickle    
listname = [1,2,3,4]    
with open('filename.pkl', 'wb') as f:
    pickle.dump(listname, f)

你可以用pickle.load()来回读它。