Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

python - 如何在列表列表中列出元素的有序频率列表(How do I make a list of the ordered frequency of elements in a list of list)

So I want to make a function that gives as return-value a list with the ordered frequency of these names.

(因此,我想制作一个函数,以这些名称的有序频率给出list作为返回值。)

Essentially all these sublist represent a pair of friends and I want to make a list of the most popular to the least popular person.

(基本上所有这些子列表都代表一对朋友,我想list一个最受欢迎的list至最不受欢迎的list 。)

I've tried many things but these sublists are giving me problems.

(我尝试了很多事情,但是这些子列表给我带来了问题。)

a = [['Marie', 'Lucas'], ['Lucas', 'Patsy'], ['Emma', 'Lucas'], ['Emma', 'Kevin'], ['Peter', 'Emma'], ['Peter', 'Lucas'], ['Peter', 'Julie'], ['Suzy', 'Tobias']]
  ask by matens translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

So we have a list of lists.

(因此,我们有一个列表列表。)

We can iterate through them like follows:

(我们可以像下面这样遍历它们:)

for list in lists:
    for name in list:
        ....

Then we could continue with counting names and keeping track of the frequency in a dict.

(然后,我们可以继续对名称进行计数,并在字典中跟踪频率。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...