How to make a histogram from a list of strings in Python?

前端 未结 8 1255
说谎
说谎 2020-12-03 04:29

I have a list of strings:

a = [\'a\', \'a\', \'a\', \'a\', \'b\', \'b\', \'c\', \'c\', \'c\', \'d\', \'e\', \'e\', \'e\', \'e\', \'e\']

I w

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 05:14

    this was a while ago so i'm not sure if you still need help but other people might so i'm here. if you're allowed to use matplotlib i think there's a much simpler solution!

    a = ['a', 'a', 'a', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'e', 'e', 'e', 'e', 'e']
    
    import matplotlib.pyplot as plt
    plt.hist(a) #gives you a histogram of your array 'a'
    plt.show() #finishes out the plot
    

    this should get you a nice histogram! there are also more edits you can do to clean up the graph if you'd like

提交回复
热议问题