0% found this document useful (0 votes)
2 views7 pages

Python List Operations Assignment

The document outlines two Python programs: one for manipulating employee records using list operations such as splitting, adding, removing, merging, updating salaries, and sorting, and another for converting a sentence into a word list and reversing it. Key methods discussed include list slicing, append(), pop(), list concatenation, list comprehension for salary updates, and the reverse() method. The document provides technical explanations for each operation performed in the programs.

Uploaded by

samie3068536
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

Python List Operations Assignment

The document outlines two Python programs: one for manipulating employee records using list operations such as splitting, adding, removing, merging, updating salaries, and sorting, and another for converting a sentence into a word list and reversing it. Key methods discussed include list slicing, append(), pop(), list concatenation, list comprehension for salary updates, and the reverse() method. The document provides technical explanations for each operation performed in the programs.

Uploaded by

samie3068536
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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.

You might also like