【发布时间】:2021-03-07 14:30:23
【问题描述】:
我有一个字符串,其中包含许多数字。字符串如下:
['# Wavelength (m) ', 'Observation: 19909', 'Observation: 27028', 'Observation: 16652', 'Observation: 31458', 'Observation: 47548', 'Observation: 21100', 'Observation: 11768', 'Observation: 36969', 'Observation: 36656', 'Observation: 14915', 'Observation: 16766', 'Observation: 18197', 'Observation: 30915', 'Observation: 41090', 'Observation: 48054', 'Observation: 39451', 'Observation: 36999', 'Observation: 23674', 'Observation: 23095', 'Observation: 30768', 'Observation: 31991', 'Observation: 31544', 'Observation: 38008', 'Observation: 16076', 'Observation: 43937', 'Observation: 42251', 'Observation: 36537', 'Observation: 15338', 'Observation: 23522', 'Observation: 47565\n']
如何仅从该字符串中提取数字?我希望之后能够按升序对这些数字进行排序。
另外,我有一个如下的 numpy 列表:
v_list = [] # will store the velocities's in this list
#Between these lines of code there is a function defined which returns some parameters and does a calculation to work out the velocities
velocity_database=v_list.append(v_kms) # store velocity of the galaxy at the end of the growing list of velocities
print("The velocities are",v_list)
给出这个控制台响应:
The velocities are [23776.307252936745, 29131.102361319136, 31615.49519071778, 17021.094456442446, 18172.375147257782, 31445.40515744717, 12649.6243034793, 14562.29510500802, 15974.290956463285, 16857.779678784023, 17837.097387347385, 20559.403621751506, 25351.46462858142, 20243.658821061777, 31645.67231184538, 23414.882588799854, 24994.813874811956, 32256.096602708625, 35258.16983158886, 26024.330289709895, 23181.488351828662, 17062.733161445263, 32680.9979695023, 21874.728746293586, 13398.338349854597, 19380.382584101142, 18428.479732444466, 19193.317697089064, 5364.615429193248, 11306.957725232642]
如何打印具有这些速度升序的新列表?
【问题讨论】:
-
这是一个 Python 列表和字符串任务。
numpy没有帮助。