his might be a good place to bring in some general discrete math terminology that makes our problem specifications less ambiguous. A substring of a string consists of characters taken in order from consecutive positions. Contrast this with the similar concept of subsequence of characters still taken in order, but not necessarily at consecutive positions. For example, each of the five strings '', 'e', 'put', 'ompu' and 'computer' is both a substring and subsequence of the string 'computer', whereas 'cper' and 'out' are subsequences but not substrings.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Words that contain given letter sequence
def words_with_letters(words, letters):


This might be a good place to bring in some general discrete math terminology that makes our problem specifications less ambiguous. A substring of a string consists of characters taken in order from consecutive positions. Contrast this with the similar concept of subsequence of characters still taken in order, but not necessarily at consecutive positions. For example, each of the five strings '', 'e', 'put', 'ompu' and 'computer' is both a substring and subsequence of the string 'computer', whereas 'cper' and 'out' are subsequences but not substrings.

 

Note how the empty string is automatically a substring of every possible string. Every string is always its own substring, although not a proper substring the same way how all other substrings are proper. Concepts of sublist and subsequence are defined for lists in an analogous manner.
Since sets have no internal order on top of the element membership in that set, sets can meaningfully have both proper and improper subsets, whereas the concept of subsequence would be nonsensical for sets and dictionaries.

Now that you know all that, given a list of words sorted in alphabetical order, and a string of required letters, find and return the list of words that contain letters as a subsequence.

letters
Expected result (using the wordlist words_sorted.txt)
'klore'
['booklore', 'booklores', 'folklore', 'folklores',
'kaliborite', 'kenlore', 'kiloampere',
'kilocalorie', 'kilocurie', 'kilogramme',
'kilogrammetre', 'kilolitre', 'kilometrage',
'kilometre', 'kilooersted', 'kiloparsec',
'kilostere',
'kiloware']
['bronchiectatic', 'bronchiogenic', 'bronchitic',
ombrophilic', 'timbrophilic']
'azaz'
['azazel', 'azotetrazole', 'azoxazole',
'diazoaminobenzene', 'hazardize', 'razzmatazz']
Transcribed Image Text:letters Expected result (using the wordlist words_sorted.txt) 'klore' ['booklore', 'booklores', 'folklore', 'folklores', 'kaliborite', 'kenlore', 'kiloampere', 'kilocalorie', 'kilocurie', 'kilogramme', 'kilogrammetre', 'kilolitre', 'kilometrage', 'kilometre', 'kilooersted', 'kiloparsec', 'kilostere', 'kiloware'] ['bronchiectatic', 'bronchiogenic', 'bronchitic', ombrophilic', 'timbrophilic'] 'azaz' ['azazel', 'azotetrazole', 'azoxazole', 'diazoaminobenzene', 'hazardize', 'razzmatazz']
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Declaring and Defining the Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education