Quick assignment: Lists For this assignment, you must create and make use of lists and master the basic skills in() and append(). 1. Create a new list. The list should be called "colour_list". The list should contain the following items: Red, Blue, Purple, Green, Orange, Beige, Peach. 2. Create another list now, which is called "fruit_list". This list should contain: Apple, Banana, Orange, Prune, Pineapple Peach. 3. Print both lists 4. Now create a new EMPTY list and call it "fruits_that_are_colours" 5. Iterate (using a for loop) through the first list, and check whether it is in the second list. if it is, add it to the third list with append() 6. Now print the list of fruits that are colours. Done. For a little extra challenge (optional), make use of functions to make the code slicker. Try to keep your main code as only calls to functions. Take note that lists created INSIDE functions will not "exist" outside of the functions unless you define them as global variables. However, if you define a list outside a function, it can be modified outside

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 2PE
icon
Related questions
Question

Programming

Title
Always all these lists. bla bla always lists...
Quick assignment: Lists
For this assignment, you must create and make use of lists and master the basic skills in() and
append().
1. Create a new list. The list should be called "colour_list". The list should contain the following
items: Red, Blue, Purple, Green, Orange, Beige, Peach.
2. Create another list now, which is called "fruit_list". This list should contain: Apple, Banana,
Orange, Prune, Pineapple Peach.
3. Print both lists
4. Now create a new EMPTY list and call it "fruits_that_are_colours"
5. Iterate (using a for loop) through the first list, and check whether it is in the second list. if it
is, add it to the third list with append()
6. Now print the list of fruits that are colours.
Done.
For a little extra challenge (optional), make use of functions to make the code slicker. Try to keep
your main code as only calls to functions.
Take note that lists created INSIDE functions will not "exist" outside of the functions unless you
define them as global variables. However, if you define a list outside a function, it can be modified
outside
For even more of a challenge, totally optional...
Make use of list comprehension and timeit to determine the computational advantage by using list
comprehension.
Repeat the exercise making use of tuples
Transcribed Image Text:Title Always all these lists. bla bla always lists... Quick assignment: Lists For this assignment, you must create and make use of lists and master the basic skills in() and append(). 1. Create a new list. The list should be called "colour_list". The list should contain the following items: Red, Blue, Purple, Green, Orange, Beige, Peach. 2. Create another list now, which is called "fruit_list". This list should contain: Apple, Banana, Orange, Prune, Pineapple Peach. 3. Print both lists 4. Now create a new EMPTY list and call it "fruits_that_are_colours" 5. Iterate (using a for loop) through the first list, and check whether it is in the second list. if it is, add it to the third list with append() 6. Now print the list of fruits that are colours. Done. For a little extra challenge (optional), make use of functions to make the code slicker. Try to keep your main code as only calls to functions. Take note that lists created INSIDE functions will not "exist" outside of the functions unless you define them as global variables. However, if you define a list outside a function, it can be modified outside For even more of a challenge, totally optional... Make use of list comprehension and timeit to determine the computational advantage by using list comprehension. Repeat the exercise making use of tuples
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Operations of Linked List
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT