All print output should include descriptions as shown in the example output below. a. Create an empty list called list1 b. Populate list1 with the values 1,3,5 c. Swap the second and third elements of listl. d. Iterate over list1 and print its items. e. Create list2, initialized with the values 1,2,3,4 f. Create list3 by combining list1 and list2 (use the + operator). g. Print list3. h. Use sequence operator in to test list3 to see if it contains a 3, print True/False result (do with one line of code). i. Count the number of 3s in list3, print the result. j. Determine the index of the first 3 in list3, print the result. k. Pop this first 3 and assign it to a variable called first3, print first3. 1. Create list4, populate it with list3's sorted values, using the sorted built-in function. m. Print list3. n. Print list4. o. Slice list3 to obtain a list of the values 1,2,3 from the middle of list3, print the result. p. Determine the length of list3, print the result. q. Determine the max value of list3, print the result. r. Sort list3 (use the list sort method), print list3. s. Create list5, a list of lists, using list1 and list2 as elements of list5. t. Print list5. u. Print the value 4 contained within list5. Example output: d) Items in list1: 1 5 g) list3 is: [1, 5, 3, 1, 2, 3, 4] h) list3 contains a 3: True i) list3 contains 2 3s i) The index of the first 3 contained in list3 is 2 k) first3 = 3 m) list3 is now: [1, 5, 1, 2, 3, 4] m) list4 is: [1, 1, 2, 3, 4, 5] ) Slice of list3 is: [1, 2, 3] ) Length of list3 is 6 a) The max value in list3 is 5 r) Sorted list3 is: [1, 1, 2, 3, 4, 5] t) list5 is: [[1, 5, 3], [1, 2, 3, 4]] u) Value 4 from list5: 4

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

Pyth please

### List Operations and Manipulations

#### Instructions
1. **Create an empty list called `list1`.**
2. **Populate `list1` with the values 1, 3, 5.**
3. **Swap the second and third elements of `list1`.**
4. **Iterate over `list1` and print its items.**
5. **Create `list2`, initialized with the values `[1, 2, 3, 4]`.**
6. **Create `list3` by combining `list1` and `list2` (use the `+` operator).**
7. **Print `list3`.**
8. **Use a sequence operator to test if `list3` contains a 3, print True/False in one line.**
9. **Count the number of 3s in `list3` and print the result.**
10. **Determine the index of the first 3 in `list3` and print the result.**
11. **Pop the first 3 from `list3`, assign it to `first3`, and print `first3`.**
12. **Create `list4`, populate it with `list3`'s sorted values using the `sorted` function.**
13. **Print `list4`.**
14. **Print `list3`.**
15. **Slice `list3` to obtain `[1, 2, 3]` from the middle, print the result.**
16. **Determine the length of `list3` and print it.**
17. **Determine the maximum value in `list3` and print it.**
18. **Sort `list3` with the `sort` method and print `list3`.**
19. **Create `list5`, a list of lists using `list1` and `list2` as elements of `list5`.**
20. **Print `list5`.**
21. **Print the value 4 contained within `list5`.**

#### Example Output
- **d) Items in `list1`:**
  ```
  1
  5
  3
  ```
- **g) `list3` is: `[1, 5, 3, 1, 2, 3, 4]`**
- **h) `list3` contains a 3: True**
- **i
Transcribed Image Text:### List Operations and Manipulations #### Instructions 1. **Create an empty list called `list1`.** 2. **Populate `list1` with the values 1, 3, 5.** 3. **Swap the second and third elements of `list1`.** 4. **Iterate over `list1` and print its items.** 5. **Create `list2`, initialized with the values `[1, 2, 3, 4]`.** 6. **Create `list3` by combining `list1` and `list2` (use the `+` operator).** 7. **Print `list3`.** 8. **Use a sequence operator to test if `list3` contains a 3, print True/False in one line.** 9. **Count the number of 3s in `list3` and print the result.** 10. **Determine the index of the first 3 in `list3` and print the result.** 11. **Pop the first 3 from `list3`, assign it to `first3`, and print `first3`.** 12. **Create `list4`, populate it with `list3`'s sorted values using the `sorted` function.** 13. **Print `list4`.** 14. **Print `list3`.** 15. **Slice `list3` to obtain `[1, 2, 3]` from the middle, print the result.** 16. **Determine the length of `list3` and print it.** 17. **Determine the maximum value in `list3` and print it.** 18. **Sort `list3` with the `sort` method and print `list3`.** 19. **Create `list5`, a list of lists using `list1` and `list2` as elements of `list5`.** 20. **Print `list5`.** 21. **Print the value 4 contained within `list5`.** #### Example Output - **d) Items in `list1`:** ``` 1 5 3 ``` - **g) `list3` is: `[1, 5, 3, 1, 2, 3, 4]`** - **h) `list3` contains a 3: True** - **i
Expert Solution
Step 1

Python code:-

 

list1 = []

list1.append(1)
list1.append(5)
list1.append(3)

#To the Create list2 and populate it with the values 1,2,3,4
list2 = [1,2,3,4]

#To the Create list3 by using + (a plus sign) to combine list1 and list2. Print list3.
list3 = list1 + list2
print("g) list3 is: ", end=" ")
print(list3)

print("h) list3 contains a 3: ", end=" ")
print(3 in list3)

#To the Count the number of 3s in list3, print the result.
print("i) list3 contains", end=" ")
print(list3.count(3), end=" ")
print("3s")

print("j) The index of the first 3 contained in list3 is ", end=" ")
print(list3.index(3))

#Pop this first 3 and assign it to a variable called first3, print first3.
first3 = list3.pop(list3.index(3))
print("k) first3 =", end=" ")
print(first3)

#To the Create list4, populate it with list3's sorted values, using the sorted built-in function.
list4 = sorted(list3)

#Print list3 and list4.
print("m) list3 is now: ", end=" ")
print(list3)
print("n) list4 is: ", end=" ")
print(list4)

print("o) Slice of list3 is: ", end=" ")
print(list3[2:5])

#Determine the length of list3, print the result.
print("p) Length of list3 is ", end=" ")
print(len(list3))

print("q) The max value in list3 is ", end=" ")
print(max(list3))

# Sort list3 (use the list sort method), print list3.
print("r) Sorted list3 is: ", end=" ")
list3.sort()
print(list3)

# To the Create list5, a list of lists, using list1 and list2 as elements of list5, print list5.
list5 = []
list5.append(list1)
list5.append(list2)
print("t) list5 is: ", end=" ")
print(list5)

# Print the value 4 contained within list5.
print("u) Value 4 from list5: ", end=" ")
print(list5[1][3])

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Linked List Representation
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