Define a function called create_pattern_dictionary (colours_list) which takes a list of colour names as a parameter and creates a dictionary containing 9 items by looping through each element in the colours list and creating a corresponding key value item. The function returns a pattern dictionary where the key is the pattern number (an integer in the range 0 - 8 inclusive) and the value is a tuple containing two integers and a colour name. The first integer is a row number (0 - 2 inclusive) and the second number is a column number (0-2) inclusive) For example, the following code fragment: colours ['red', 'green', 'blue', 'aqua', 'brown', 'darkseagreen', 'purple', 'lavender', 'magenta'] pattern_dictionary = create_pattern_dictionary(colours) print (pattern_dictionary) produces: (0: (0, 0, 'red'), 1: (0, 1, 'green'), 2: (0, 2, 'blue'), 3: (1, 0, 'aqua'), 4: (1, 1, 'brown'), 5: (1, 2, 'darkseagreen'), 6: (2, 0, 'purple'), 7: (2, 1, 'lavender'), 8: (2, 2, 'magenta')} For example: Test Result (0, 0, 'red') colours ['red', 'green', 'blue', 'aqua', 'brown', 'darkseagreen', 'purple', 'lavender', 'magenta'] pattern_dictionary create_pattern_dictionary(colours) 1 (0, 1, 'green') for key in sorted (pattern_dictionary.keys()): 2 (0, 2, 'blue') print (key, pattern_dictionary [key]) 3 (1, 0, 'aqua') 4 (1, 1, 'brown') 5 (1, 2, 'darkseagreen') 6 (2, 0, 'purple') 7 (2, 1, 'lavender') 8 (2, 2, 'magenta') colours = ['blanchedalmond', 'darkseagreen', 'orange', 'turquoise', 'blue', 'teal', 'yellow', 'brown', 'gray'] pattern_dictionary = create_pattern_dictionary (colours) print (type(pattern_dictionary [0])) values pattern_dictionary [0] print (type(values[0])) print (type(values[1])) print (type(values[2]))

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
Define a function called create_pattern_dictionary (colours_list) which takes a list of colour names as a parameter and creates a dictionary containing 9 items by looping through
each element in the colours list and creating a corresponding key value item. The function returns a pattern dictionary where the key is the pattern number (an integer in the range 0 - 8
inclusive) and the value is a tuple containing two integers and a colour name. The first integer is a row number (0 - 2 inclusive) and the second number is a column number (0 - 2
inclusive) For example, the following code fragment:
colours = ['red', 'green', 'blue',
'aqua', 'brown', 'darkseagreen',
'purple', 'lavender', 'magenta']
pattern_dictionary = create_pattern_dictionary (colours)
print (pattern_dictionary)
produces:
{0: (0, 0, 'red'), 1: (0, 1, 'green'), 2: (0, 2, 'blue'),
3: (1, 0, 'aqua'), 4: (1, 1, 'brown'), 5: (1, 2, 'darkseagreen'),
6: (2, 0, 'purple'), 7: (2, 1, 'lavender'), 8: (2, 2, 'magenta')}
For example:
Test
Result
0 (0, 0, 'red')
colours = ['red', 'green', 'blue', 'aqua', 'brown', 'darkseagreen', 'purple', 'lavender', 'magenta']
pattern_dictionary = create_pattern_dictionary (colours)
1 (0, 1, 'green')
for key in sorted (pattern_dictionary.keys ()):
2 (0, 2, 'blue')
print(key, pattern_dictionary [key])
3 (1, 0, 'aqua')
4 (1, 1, 'brown')
5 (1, 2, 'darkseagreen')
6 (2, 0, 'purple')
7 (2, 1, 'lavender')
8 (2, 2, 'magenta')
colours = ['blanchedalmond', 'darkseagreen', 'orange', 'turquoise', 'blue', 'teal', 'yellow', 'brown', 'gray'] <class 'tuple'>
pattern_dictionary = create_pattern_dictionary (colours)
print (type(pattern_dictionary [0]))
<class 'int'>
<class 'int'>
<class 'str'>
values = pattern_dictionary [0]
print (type (values[0]))
print (type (values[1]))
print (type(values[2]))
Transcribed Image Text:Define a function called create_pattern_dictionary (colours_list) which takes a list of colour names as a parameter and creates a dictionary containing 9 items by looping through each element in the colours list and creating a corresponding key value item. The function returns a pattern dictionary where the key is the pattern number (an integer in the range 0 - 8 inclusive) and the value is a tuple containing two integers and a colour name. The first integer is a row number (0 - 2 inclusive) and the second number is a column number (0 - 2 inclusive) For example, the following code fragment: colours = ['red', 'green', 'blue', 'aqua', 'brown', 'darkseagreen', 'purple', 'lavender', 'magenta'] pattern_dictionary = create_pattern_dictionary (colours) print (pattern_dictionary) produces: {0: (0, 0, 'red'), 1: (0, 1, 'green'), 2: (0, 2, 'blue'), 3: (1, 0, 'aqua'), 4: (1, 1, 'brown'), 5: (1, 2, 'darkseagreen'), 6: (2, 0, 'purple'), 7: (2, 1, 'lavender'), 8: (2, 2, 'magenta')} For example: Test Result 0 (0, 0, 'red') colours = ['red', 'green', 'blue', 'aqua', 'brown', 'darkseagreen', 'purple', 'lavender', 'magenta'] pattern_dictionary = create_pattern_dictionary (colours) 1 (0, 1, 'green') for key in sorted (pattern_dictionary.keys ()): 2 (0, 2, 'blue') print(key, pattern_dictionary [key]) 3 (1, 0, 'aqua') 4 (1, 1, 'brown') 5 (1, 2, 'darkseagreen') 6 (2, 0, 'purple') 7 (2, 1, 'lavender') 8 (2, 2, 'magenta') colours = ['blanchedalmond', 'darkseagreen', 'orange', 'turquoise', 'blue', 'teal', 'yellow', 'brown', 'gray'] <class 'tuple'> pattern_dictionary = create_pattern_dictionary (colours) print (type(pattern_dictionary [0])) <class 'int'> <class 'int'> <class 'str'> values = pattern_dictionary [0] print (type (values[0])) print (type (values[1])) print (type(values[2]))
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
Define a function called create_pattern_dictionary (colours_list) which takes a list of colour names as a parameter and creates a dictionary containing 9 items by looping through
each element in the colours list and creating a corresponding key: value item. The function returns a pattern dictionary where the key is the pattern number (an integer in the range 0 - 8
inclusive) and the value is a tuple containing two integers and a colour name. The first integer is a row number (0 - 2 inclusive) and the second number is a column number (0 - 2
inclusive) For example, the following code fragment:
colours = ['red', 'green', 'blue',
'aqua', 'brown', 'darkseagreen',
'purple', 'lavender', 'magenta']
pattern_dictionary = create_pattern_dictionary (colours)
print (pattern_dictionary)
produces:
{0: (0, 0, 'red'), 1: (0, 1, 'green'), 2: (0, 2, 'blue'),
3: (1, 0, 'aqua'), 4: (1, 1, 'brown'), 5: (1, 2, 'darkseagreen'),
6: (2, 0, 'purple'), 7: (2, 1, 'lavender'), 8: (2, 2, 'magenta')}
For example:
Test
Result
0 (0, 0, 'red')
colours = ['red', 'green', 'blue', 'aqua', 'brown', 'darkseagreen', 'purple', 'lavender', 'magenta']
pattern_dictionary = create_pattern_dictionary (colours)
1 (0, 1, 'green')
for key in sorted (pattern_dictionary.keys()):
2 (0, 2, 'blue')
print(key, pattern_dictionary [key])
3 (1, 0, 'aqua')
4 (1, 1, 'brown')
5 (1, 2, 'darkseagreen')
6 (2, 0, 'purple')
7 (2, 1, 'lavender')
8 (2, 2, 'magenta')
colours = ['blanchedalmond', 'darkseagreen', 'orange', 'turquoise', 'blue', 'teal', 'yellow', 'brown', 'gray'] <class 'tuple'>
pattern_dictionary = create_pattern_dictionary (colours)
print (type(pattern_dictionary[0]))
<class 'int'>
<class 'int'>
<class 'str'>
values= pattern_dictionary [0]
print (type (values[0]))
print (type(values[1]))
print (type (values [2]))
Transcribed Image Text:Define a function called create_pattern_dictionary (colours_list) which takes a list of colour names as a parameter and creates a dictionary containing 9 items by looping through each element in the colours list and creating a corresponding key: value item. The function returns a pattern dictionary where the key is the pattern number (an integer in the range 0 - 8 inclusive) and the value is a tuple containing two integers and a colour name. The first integer is a row number (0 - 2 inclusive) and the second number is a column number (0 - 2 inclusive) For example, the following code fragment: colours = ['red', 'green', 'blue', 'aqua', 'brown', 'darkseagreen', 'purple', 'lavender', 'magenta'] pattern_dictionary = create_pattern_dictionary (colours) print (pattern_dictionary) produces: {0: (0, 0, 'red'), 1: (0, 1, 'green'), 2: (0, 2, 'blue'), 3: (1, 0, 'aqua'), 4: (1, 1, 'brown'), 5: (1, 2, 'darkseagreen'), 6: (2, 0, 'purple'), 7: (2, 1, 'lavender'), 8: (2, 2, 'magenta')} For example: Test Result 0 (0, 0, 'red') colours = ['red', 'green', 'blue', 'aqua', 'brown', 'darkseagreen', 'purple', 'lavender', 'magenta'] pattern_dictionary = create_pattern_dictionary (colours) 1 (0, 1, 'green') for key in sorted (pattern_dictionary.keys()): 2 (0, 2, 'blue') print(key, pattern_dictionary [key]) 3 (1, 0, 'aqua') 4 (1, 1, 'brown') 5 (1, 2, 'darkseagreen') 6 (2, 0, 'purple') 7 (2, 1, 'lavender') 8 (2, 2, 'magenta') colours = ['blanchedalmond', 'darkseagreen', 'orange', 'turquoise', 'blue', 'teal', 'yellow', 'brown', 'gray'] <class 'tuple'> pattern_dictionary = create_pattern_dictionary (colours) print (type(pattern_dictionary[0])) <class 'int'> <class 'int'> <class 'str'> values= pattern_dictionary [0] print (type (values[0])) print (type(values[1])) print (type (values [2]))
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Lists
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
  • SEE MORE 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