Giter Club home page Giter Club logo

rolodex's Introduction

Rolodex

Rolodex is a small coding project for Percolate (https://percolate.com/). This program is taking entries of personal information in multiple formats and normalizing each entry into a standard JSON format.

Usage

In the src folder:
$ python rolodex.py -f ../tests/sample.in -o result.out

For all options, take a look at:
$ python rolodex.py -h

Run Tests

In the project root:
$ python -m unittest discover

The Problem

You’re tasked with taking entries of personal information in multiple formats and normalizing each entry into a standard JSON format. Write your formatted, valid JSON out to a file with two-space indentation and keys sorted alphabetically.

Input

Your program will be fed an input file of n lines. Each line contains “entry” information, which consists of a first name, last name, phone number, color, and zip code. The order and format of these lines vary in three separate ways. The three different formats are as follows:

Lastname, Firstname, (703)-742-0996, Blue, 10013
Firstname Lastname, Red, 11237, 703 955 0373
Firstname, Lastname, 10013, 646 111 0101, Green

Some lines may be invalid and should not interfere with the processing of subsequent valid lines. A line should be considered invalid if its phone number does not contain the proper number of digits.

Output

The program should write a valid, formatted JSON object out to result.out. The JSON representation should be indented with two spaces and the keys should be sorted in ascending order. Successfully processed lines should result in a normalized addition to the list associated with the “entries” key. For lines that were unable to be processed, a line number i (where 0 ≤ i < n) for each faulty line should be appended to the list associated with the “errors” key. The “entries” list should be sorted in ascending alphabetical order by (last name, first name). The complete output schema is specified below.

Sample

For the input:

Booker T., Washington, 87360, 373 781 7380, yellow
Chandler, Kerri, (623)-668-9293, pink, 123123121
James Murphy, yellow, 83880, 018 154 6474
asdfawefawea

we should receive the output:
{
"entries": [
{
"color": "yellow",
"firstname": "James",
"lastname": "Murphy",
"phonenumber": "018-154-6474",
"zipcode": "83880"
},
{
"color": "yellow",
"firstname": "Booker T.",
"lastname": "Washington",
"phonenumber": "373-781-7380",
"zipcode": "87360"
}
],
"errors": [
1,
3
]
}

rolodex's People

Contributors

raphi avatar

Watchers

 avatar  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.