Question

python Given a list Lst = [“bye”, “hi”, “good”, “okay”, “sad”], write codes for each of...

python

Given a list Lst = [“bye”, “hi”, “good”, “okay”, “sad”], write codes for each of the following tasks:

            Add “happy” to the end of the list

Add "nice" to the beginning of the list

            Replace “hi” with “hello”

0 0
Add a comment Improve this question Transcribed image text
Answer #1

WHen we insert an item into list by list.append(item) method then by default that item is added in the end of the list.

So to add happy to the end of the list I have just used Lst.append("happy")

To add an element in begning of the list we have to use Lst.insert(0,item) code . here 0 indicate the index where insertion will be done. Now if you want to insert item at begning then index of begning is 0 will be mentioned.

We have to replace "hi" wilth hello so for that we have to use Lst[1]="hello" . Where 1 is index of item where we want to make the change.

Add a comment
Know the answer?
Add Answer to:
python Given a list Lst = [“bye”, “hi”, “good”, “okay”, “sad”], write codes for each of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Language: Python 3.6 Include Comments in the code - Given the following list: myList = ["Hello",...

    Language: Python 3.6 Include Comments in the code - Given the following list: myList = ["Hello", "name", 6, 3.1, 7.2, 9.4, "Good bye", 11.1, 22] Write a program that will total the numbers only

  • IN PYTHON Implement a function printSeqs() that accepts a list of name lst and prints the...

    IN PYTHON Implement a function printSeqs() that accepts a list of name lst and prints the following sequences. The sequences are printed by the for loops found in the function. The information below shows how you would call the function printSeqs() and what it would display: Write a for loop that iterates through a list of names and print a greeting for each name in the list. Request from the user a positive integer n and prints all the positive...

  • 1. use python List to Dictionary Write a function that has three parameters: a list of...

    1. use python List to Dictionary Write a function that has three parameters: a list of unsorted numbers with no duplicates, a start number, and an end number. This function should return a dictionary with all integers between the start and end number (inclusive) as the keys and their respective indices in the list as the value. If the integer is not in the list, the corresponding value would be None. Example unsorted list: [2,1,10,0,4,3] two numbers: 3, 10 returned...

  • use python Write a function that will sort a given list using merge sort. You must...

    use python Write a function that will sort a given list using merge sort. You must use the merge sort algorithm (but may be recursive or iterative). The function will take a list as an input and return a sorted version of the list (you may assume it will be a list of integers). The method signature must be merge_sort(lst).

  • Python recursive function: Given an ordered list L. A permutation of L is a rearrangement of...

    Python recursive function: Given an ordered list L. A permutation of L is a rearrangement of its elements in some order. For example (1,3, 2) and (3, 2, 1) are two different permutations of L=(1,2,3). Implement the following function: def permutations (lst, low, high) The function is given a list 1st of integers, and two indices: low and high (lows high), which indicate the range of indices that need to be considered The function should return a list containing all...

  • Write a single command line to accomplish the following tasks in Python 1- Count the number...

    Write a single command line to accomplish the following tasks in Python 1- Count the number of instances of each item in a list and produce another list of lists containing each item and its count. (Use the list count method) 2- Remove all words containing a capital letter at the end in a given string. (Use the join and ends with methods) 3- Remove every other letter from a string

  • Write a few lines in Python that will do the following: Create an empty list Ask...

    Write a few lines in Python that will do the following: Create an empty list Ask the user to enter two numbers Add each number to your list

  • Question 1 You are given a list of product codes for dog sweaters sold by Sweaters...

    Question 1 You are given a list of product codes for dog sweaters sold by Sweaters 4 Fur Friends. The codes are all 5 digits long and the last two digits in each code represents the size of the corresponding sweater. Here is a sample of the list of codes: sweaterCodes = [12309, 32109, 54204, 35410, 87508, 50404, 94307, 94306, 54205, 12303, 32111, 32110] Write a Python program in a file called SortCodes.py to sort the list of codes into...

  • Python program - Write a Python program, in a file called sortList.py, which, given a list...

    Python program - Write a Python program, in a file called sortList.py, which, given a list of names, sorts the names into alphabetical order. Use a one dimensional array to hold the list of names. To do the sorting use a simple sorting algorithm that repeatedly takes an element from the unsorted list and puts it in alphabetical order within the same list. Initially the entire list is unsorted. As each element is placed in alphabetical order, the elements in...

  • Use Python 3.7 to write the following program: Given a list of n numbers, write a...

    Use Python 3.7 to write the following program: Given a list of n numbers, write a function to shift the numbers circularly by some integer k (k < n). The function should take a list, the amount to shift k, and an argument specifying the direction to shift (left or right). Suggestion: use the % operation and also you need a number between 0 inclusive and the length of the list.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT