Giter VIP home page Giter VIP logo

python-p3-anagram-detector-lab's Introduction

Anagram Detector Lab

Learning Goals

  • Build robust and dynamic Python objects.
  • Accomplish complex programming tasks using knowledge from previous modules.

Key Vocab

  • Class: a bundle of data and functionality. Can be copied and modified to accomplish a wide variety of programming tasks.
  • Object: the more common name for an instance. The two can usually be used interchangeably.
  • Object-Oriented Programming: programming that is oriented around data (made mobile and changeable in objects) rather than functionality. Python is an object-oriented programming language.
  • Function: a series of steps that create, transform, and move data.
  • Method: a function that is defined inside of a class.

Instructions

This is a test-driven lab. Run pipenv install to create your virtual environment and pipenv shell to enter the virtual environment. Then run pytest -x to run your tests. Use these instructions and pytest's error messages to complete your work in the lib/ folder.

You will write a program that, given a word and a list of possible anagrams, selects the correct one(s).

Your class, Anagram should take a word on initialization; instances should respond to a match() instance method that takes a list of possible anagrams. It should return all matches in a list. If no matches exist, it should return an empty list.

In other words, given: 'listen' and ['enlists', 'google', 'inlets', 'banana'] the program should return ['inlets'].

listen = Anagram("listen")
listen.match(['enlists', 'google', 'inlets', 'banana'])
# => ['inlets']

Write your solution in lib/anagram.py.

Once all of your tests are passing, commit and push your work using git to submit.

This is a difficult lab that will require some algorithmic thinking! Try writing some pseudocode and break the problem down into smaller steps before writing out your implementation.

Hints:

How will you determine if one word is an anagram for another?

You'll need to iterate over the list of words that the match() method takes as an argument. You will compare each word of that list to the word that the Anagram class is initialized with.

To determine one word is an anagram of another word, try determining if they are composed of the same letters. You can use a list interpretation on a string to get a list of its individual letters:

[letter for letter in "hello"]
# ["h", "e", "l", "l", "o"]

You can compare two lists using the ==. For example:

[1, 2, 3] == [1, 2, 3]
# => True

[1, 3, 2] == [1, 2, 3]
# => False

Two lists are equal if they contain the same elements, in the same order. Remember that you can use sorted() on a list. This will help in your comparison:

sorted([1, 3, 2]) == sorted([3, 2, 1])
# => True

Resources

python-p3-anagram-detector-lab's People

Contributors

professor-ben avatar jlboba avatar lizbur10 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.