Word frequency analysis in Python returning letter frequency

后端 未结 3 632
野的像风
野的像风 2021-01-27 01:25

Following examples on other Stackoverflow posts related to word frequency analysis in Python, my program is returning letter frequency analysis and not actually the word.

<
3条回答
  •  隐瞒了意图╮
    2021-01-27 01:49

    contents is a string, and strings in Python are iterable (i.e. strings behave like lists of letters in this context) so your Counter is counting letters.

    You need to pass the Counter a list of words, not a string of letters.

    Joran's answer shows how to do this using split().

提交回复
热议问题