Python List Operations Assignment
(a) Python Program for Employee List Operations
In this scenario, we assume that a Data Analyst is required to manipulate employee records
stored in Python lists. The program performs list splitting, adding new employees, removing
employees, merging lists, updating salaries, and sorting salaries.
Output
Technical Explanation
List Splitting
Python list slicing (employees[:5] and employees[5:]) is used to divide the list into two
equal parts.
Adding Elements
The append() method adds a new element to the end of a list.
Removing Elements
The pop(index) method removes an element at a specific position. Since Python
indexing starts at 0, index 1 represents the second element.
List Merging
The + operator concatenates two lists into a single list.
Salary Update
A list comprehension is used to apply a 4% increment by multiplying each salary value
by 1.04.
Sorting
The sort(reverse=True) method sorts the list in descending order.
Top Salaries
List slicing [:3] extracts the three highest salaries.
(b) Python Program to Convert Sentence to Word List and Reverse It
This program converts a sentence into a list of words, then reverses the order of those words.
Input
Output
Technical Explanation
Sentence to Word List
The split() method converts a string into a list by separating words based on spaces.
Reversing the List
The reverse() method reverses the elements of the list in place, meaning the original list is
modified.
Result
The program first displays the list of words and then prints the reversed order of those words.