0% found this document useful (0 votes)
11 views

CS 1101 Unit 6

The document reports on changes made to employee and salary lists for a Walmart HR department. It splits an employee list into two sublists, adds a new employee, removes an existing one, merges the sublists, gives all employees a 4% raise, sorts the salary list descending, and prints the top 3 salaries. It also defines a function to reverse a sentence by splitting it into words and reversing the word order.
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)
11 views

CS 1101 Unit 6

The document reports on changes made to employee and salary lists for a Walmart HR department. It splits an employee list into two sublists, adds a new employee, removes an existing one, merges the sublists, gives all employees a 4% raise, sorts the salary list descending, and prints the top 3 salaries. It also defines a function to reverse a sentence by splitting it into words and reversing the word order.
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
You are on page 1/ 4

PART A

Report for Walmart HR department


Code:
#Existing List of employees in walmart
Walmart_employees = ["Abiodun", "Chima", "Chekwas", "David", "Eva", "Frank",
"Grace", "Hannah", "Lukmon", "Jack"]

# Splitting the list into two sublists


subList1 = Walmart_employees[:5]
subList2 = Walmart_employees[5:]

# adding a new employee using append


subList2.append("John Lukmon")

# Removing the second employee's name from subList1 using the del
del subList1[1] # Assuming the second employee is at index 1

mergedList = subList1 + subList2

# Salary list
salaryList = [50000, 55000, 60000, 65000, 70000, 75000, 80000, 85000, 90000,
95000]

# Giving a 4% raise to every employee and updating the salaryList


salaryList = [salary for salary in salaryList]

# Sorting the salaryList in descending order


salaryList.sort(reverse=True)

top_3_salaries = salaryList[:3]

print("Merged List of employees:", mergedList)


print("Updated Salary List for employees:", salaryList)
print("Top 3 Salaries in the company:", top_3_salaries)

Code Output
Explanation:

 Two sublists, ‘sublist1’ and ‘sublist2’, are created by splitting the


‘Walmart_employees’ list into two halves.
 "Kriti Brown" is added to ‘sublist2’.
 The second employee's name is removed from ‘sublist1’ using the ‘del’ operator.
 Both sublists are merged into ‘mergedlist’.
 ‘salary_list’ is given a 4% raise using list comprehension.
 The ‘sort()’ method is used to sort ‘salarylist’ in descending order, and the top 3 salaries
are extracted.
Part b
Code:
# Defining a function to convert a sentence into a word list and reverse it
def wordlist_reverse(sentence):
word_list = sentence.split() # Splitting the sentence into words
reversed_list = list(reversed(word_list) ) # Reversing the word list
return reversed_list

# Sentence
input_sentence = "I really do love my food in the freezer"

# Converting the sentence into a word list and reversing it


reversed_words = wordlist_reverse(input_sentence)

print("Original Sentence:", input_sentence)


print("Reversed Word List:", reversed_words)

Output:

Explanation:

 The defined wordlist_reverse( ) function takes a sentence as input, splits it into a word
list using split() , and reverses the list using reversed() and list() functions.
 The sample sentence is converted into a word list, and its reversed form is displayed as
seen in the screenshot above.

You might also like