GithubHelp home page GithubHelp logo

word_counter_exercise's Introduction

Programming Exercise

Description

Question

Given a comma seperated list of words in a single file, return the number of times the word was seen.

The input will be in the form of a text file.

Example input

green,green,red,green,red

Expected output

green,3
red,2

Input Assumptions

  1. leading and trailing "," is ignored, ",," is ignored
  2. word length is not checked. max word length is python array size limit. 536870912 on a 32 bit system
  3. all characters are assumed ascii characters

Requirement

python3.6 and above

To check python version:

$ python --version
Python 3.7.1

Usage

From project root directory,

$ python count_word.py input_file word1 word2 ...

Example:

$ python count_word.py tests/data/case1.in ab bc
ab,2
bc,2

$ python count_word.py tests/data/case1.in ab bc f
ab,2
bc,2
f,0

Tests

To run test, issue folowing command from project directory

$ python -m unittest discover tests
......
----------------------------------------------------------------------
Ran 6 tests in 0.007s

OK

To add more test cases, refer to existing test files in tests/data.

Each test case consists of 2 files, *.in and *.cmp. The two file names must match.

  1. *.in is input file with only one line in the file, for example green,green,red,red.
  2. *.cmp is the truth file for comparison, each line is a word and its occurance seperated by comma.

word_counter_exercise's People

Contributors

hazelement avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.