84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
针对爬虫结果的列表,应当如何处理才能进行合并,试过一些方法都不是预期的效果我希望的效果是将:【‘犯罪’】【‘犯罪’,‘剧情’】……合并成:【‘犯罪’,‘犯罪’,‘剧情’……】最终目的是进行出现频率的统计。谢谢指点!
人生最曼妙的风景,竟是内心的淡定与从容!
Put count_times=[] outside the big loop (the first loop), and then count
print dict([(i,count_times.count(i)) for i in set(count_times)])
If your goal is to count the frequency of occurrence, you can use Counter in collectionsAs shown in the picture
Just use a dictionary to count
In [1]: b, a = {}, [1, 2, 3, 4, 5, 6] In [2]: [b.update({key: b[key] + 1}) if key in b.keys() else b.update({key: 1}) for key in a] Out[2]: [None, None, None, None, None, None] In [3]: b Out[3]: {1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1}
Counter can also display the list after statistics
Put count_times=[] outside the big loop (the first loop), and then count
If your goal is to count the frequency of occurrence, you can use Counter in collections
As shown in the picture
Just use a dictionary to count
Counter can also display the list after statistics