Word count graphSplit and word count in goWord count program in JavaExercism assignment word-count in...

How do I deal with a powergamer in a game full of beginners in a school club?

Unreachable code, but reachable with exception

Look through the portal of every day

How much attack damage does the AC boost from a shield prevent on average?

How do I locate a classical quotation?

Things to avoid when using voltage regulators?

PTIJ: Why can't I eat anything?

What are some noteworthy "mic-drop" moments in math?

Virginia employer terminated employee and wants signing bonus returned

Do I really need to have a scientific explanation for my premise?

infinitive telling the purpose

The bar has been raised

Why would a jet engine that runs at temps excess of 2000°C burn when it crashes?

Do f-stop and exposure time perfectly cancel?

Replacing Windows 7 security updates with anti-virus?

Does splitting a potentially monolithic application into several smaller ones help prevent bugs?

Rejected in 4th interview round citing insufficient years of experience

"One can do his homework in the library"

In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?

PTIJ: How can I halachically kill a vampire?

How to pass a string to a command that expects a file?

Is there any way to damage Intellect Devourer(s) when already within a creature's skull?

Solving "Resistance between two nodes on a grid" problem in Mathematica

Why does Deadpool say "You're welcome, Canada," after shooting Ryan Reynolds in the end credits?



Word count graph


Split and word count in goWord count program in JavaExercism assignment word-count in Python.txt word-counterCount every word occurrence from fileWord count and most frequent words from input text, excluding stop wordsPython Word definition practiceProgram to count vowelsCamelCase word countPreprocess HTML input and generate word count













0












$begingroup$


I created a program in python that reads a file and outputs a frequency graph of the words it contains. Any feedback or tips would be appreciated.



from re import split
from collections import Counter

size = int(input("Output window size(in chars): "))
with open("text.txt", "r") as f:
words = [w for w in split(r"[W_d]+", f.read().strip()) if w]
if not words:
print("Put some text in `text.txt`!")
quit()
word_count = Counter(words)
top_words = sorted(word_count.keys(), key = lambda w : word_count[w], reverse = True)
scale = (size - len(max(top_words, key = len))) / word_count[top_words[0]]
for word in top_words[:10]:
print("-" * (int(word_count[word] * scale) - 2) + "| " + word)









share|improve this question









$endgroup$

















    0












    $begingroup$


    I created a program in python that reads a file and outputs a frequency graph of the words it contains. Any feedback or tips would be appreciated.



    from re import split
    from collections import Counter

    size = int(input("Output window size(in chars): "))
    with open("text.txt", "r") as f:
    words = [w for w in split(r"[W_d]+", f.read().strip()) if w]
    if not words:
    print("Put some text in `text.txt`!")
    quit()
    word_count = Counter(words)
    top_words = sorted(word_count.keys(), key = lambda w : word_count[w], reverse = True)
    scale = (size - len(max(top_words, key = len))) / word_count[top_words[0]]
    for word in top_words[:10]:
    print("-" * (int(word_count[word] * scale) - 2) + "| " + word)









    share|improve this question









    $endgroup$















      0












      0








      0





      $begingroup$


      I created a program in python that reads a file and outputs a frequency graph of the words it contains. Any feedback or tips would be appreciated.



      from re import split
      from collections import Counter

      size = int(input("Output window size(in chars): "))
      with open("text.txt", "r") as f:
      words = [w for w in split(r"[W_d]+", f.read().strip()) if w]
      if not words:
      print("Put some text in `text.txt`!")
      quit()
      word_count = Counter(words)
      top_words = sorted(word_count.keys(), key = lambda w : word_count[w], reverse = True)
      scale = (size - len(max(top_words, key = len))) / word_count[top_words[0]]
      for word in top_words[:10]:
      print("-" * (int(word_count[word] * scale) - 2) + "| " + word)









      share|improve this question









      $endgroup$




      I created a program in python that reads a file and outputs a frequency graph of the words it contains. Any feedback or tips would be appreciated.



      from re import split
      from collections import Counter

      size = int(input("Output window size(in chars): "))
      with open("text.txt", "r") as f:
      words = [w for w in split(r"[W_d]+", f.read().strip()) if w]
      if not words:
      print("Put some text in `text.txt`!")
      quit()
      word_count = Counter(words)
      top_words = sorted(word_count.keys(), key = lambda w : word_count[w], reverse = True)
      scale = (size - len(max(top_words, key = len))) / word_count[top_words[0]]
      for word in top_words[:10]:
      print("-" * (int(word_count[word] * scale) - 2) + "| " + word)






      python python-3.x strings






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 42 mins ago









      All KnowerAll Knower

      1486




      1486






















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215307%2fword-count-graph%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215307%2fword-count-graph%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

          How do i solve the “ No module named 'mlxtend' ” issue on Jupyter?

          Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...