Python 根据分数重新排列列表项以拟合函数曲线

Python 根据分数重新排列列表项以拟合函数曲线,python,list,sorting,curve,Python,List,Sorting,Curve,鉴于我已: 词表 表示每个单词“简单”的分数/分数 每个单词的难度等级: 例如 目前,单词列表按简单程度排序点 如果我想将简单性建模为一条“二次曲线”,即从最高点到最低点,然后再回到最高点,即生成一个单词列表,该列表与相应的点类似: ['apple', 'pear', 'average', 'coefficient', 'exponential', 'older', 'values', 'apple', 'pear'] 我试过这个,但它是痛苦的疯狂: >>> from c

鉴于我已:

  • 词表
  • 表示每个单词“简单”的分数/分数
  • 每个单词的难度等级:
例如

目前,单词列表按简单程度排序

如果我想将简单性建模为一条“二次曲线”,即从最高点到最低点,然后再回到最高点,即生成一个单词列表,该列表与相应的点类似:

['apple', 'pear', 'average', 'coefficient', 'exponential', 'older', 'values', 'apple', 'pear']
我试过这个,但它是痛苦的疯狂:

>>> from collections import Counter
>>> Counter(bins)[0]
4
>>> num_easy, num_mid, num_hard = Counter(bins)[0], Counter(bins)[1], Counter(bins)[2]
>>> num_easy
4
>>> easy_words = words[:num_easy]
>>> mid_words = words[num_easy:num_easy+num_mid]
>>> hard_words = words[-num_hard:]
>>> easy_words, mid_words, hard_words
(['apple', 'pear', 'car', 'man'], ['average', 'older', 'values'], ['coefficient', 'exponential'])
>>> easy_1 = easy_words[:int(num_easy/2)]
>>> easy_2 = easy_words[len(easy_1):]
>>> mid_1 = mid_words[:int(num_mid/2)]
>>> mid_2 = mid_words[len(mid_1):]
>>> new_words = easy_1 + mid_1 + hard_words + mid_2 + easy_1 
>>> new_words
['apple', 'pear', 'average', 'coefficient', 'exponential', 'older', 'values', 'apple', 'pear']
想象一下箱子的数量>3个,或者我想用单词的“点”来拟合正弦曲线

请注意,这并不完全是一个
nlp
问题,也与“zipf”分布和创建匹配或重新排列单词排名的内容无关


假设有一个整数列表,您有一个对象(在本例中是一个单词)映射到每个整数,并且您希望对对象列表重新排序以拟合二次曲线

根据您的自定义条件将其排序到一个列表中,检查其长度是偶数还是奇数,然后将其分为两块进行压缩,并将最后一半倒转:

>>> def peak(s):
...     return s[::2]+s[-1-(len(s)%2)::-2]
...
>>> peak('112233445566778')
'123456787654321'
>>> peak('1122334455667788')
'1234567887654321'
请注意,不均匀的数据可能会产生不对称的结果:

>>> peak('11111123')
'11123111'

我会按照这些思路做某事。将单词按其要点分类,每秒钟取出一次,将一半倒转,然后将两个单词连在一起:

>>> s = sorted(zip(map(int, points), words))
>>> new_words = [word for p, word in list(reversed(s[::2])) + s[1::2]]
# If you have lots of words you'll be better off using some 
# itertools like islice and chain, but the principle becomes evident
>>> new_words
['apple', 'car', 'older', 'values', 'exponential', 'coefficient', 'average', 'man', 'pear']
按下列顺序订购:

[(9999, 'apple'), (8231, 'car'), (4712, 'older'), (500, 'values'), (5, 'exponential'), (10, 'coefficient'), (3242, 'average'), (5123, 'man'), (9231, 'pear')]

是无关的还是点的
bin
值派生出来的?bin是从点派生出来的。您提到“单词列表是按简单性排序的
”,但是
在您的示例中看起来没有顺序,因为它有子序列
'5123',3242',4712'
。我的理解有什么错误吗?@Rohanil,打字错误。更正。
[(9999, 'apple'), (8231, 'car'), (4712, 'older'), (500, 'values'), (5, 'exponential'), (10, 'coefficient'), (3242, 'average'), (5123, 'man'), (9231, 'pear')]