Question

Question 2. (PYTHON, 20 point] Change the list [1,2,3,4,5] to [2,3,4,1], and then print out the result (using add or remove f
0 0
Add a comment Improve this question Transcribed image text
Answer #1

l = [1,2,3,4,5]
print(l)
l.remove(l[-1])
k= l[0]
l.remove(k)
l.append(k)
print(l)

output:

[1,2,3,4,5]

[2,3,4,1]

Add a comment
Know the answer?
Add Answer to:
Question 2. (PYTHON, 20 point] Change the list [1,2,3,4,5] to [2,3,4,1], and then print out the...
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
  • Having trouble with python! Write a program to build a list of grades, print them out,...

    Having trouble with python! Write a program to build a list of grades, print them out, add to them and count occurrences, and find the amount of the 2-digit grade values. Here are the criteria a) Your program “L6QI initials.py" must start with a commented ID Box AND include a comment that indicates the e of the program. EACH of the five functions in your program must state its purpose in comments too The main function in your program must...

  • python #Ignore line 2, it is just there to align with zybooks requirements print("5") #Create a...

    python #Ignore line 2, it is just there to align with zybooks requirements print("5") #Create a list with the following numbers and assign it to a variable name: 1,2,3,4,5,6 #Convert the list to a tuple and assign it to a variable name (dirrerent from the list's name) #Try the following and press the run program button to which ones work and which ones cause errors #If a statement causes an error, use a # to comment it out #Add the...

  • How to remove all occurrences of 2 from list2. Then display the list. Python import random...

    How to remove all occurrences of 2 from list2. Then display the list. Python import random list1 = [] for i in range (10): list1.append(random.randint(1,4)) print('List 1:') print(list1) list2 = [] list2.append(list1[5:]) print('List 2:') print(list2) list2.remove ******** (This is the part I am having trouble on!!) print('List 2 with all 2s removed:') print(list2) Sample output: List 1: [4, 1, 1, 3, 3, 3, 2, 4, 2, 4] List2: [3, 2, 4, 2, 4] List 2 with all 2s removed: [3,...

  • Using Python. Write a function clean2(aList) that takes a list of integers aList as argument, and...

    Using Python. Write a function clean2(aList) that takes a list of integers aList as argument, and modifies this list, such as multiple occurrences of values have been removed. The procedure does not return a list: it modifies its argument (reference aList). 3 For instance, the following statements: al = [1,2,3,4,4,4,5,1,2,1,5] print(al) clean2(al) print(al) print the following result (a different order of values is acceptable): [1,2,3,4,4,4,5,1,2,1,5] [1,2,3,4,5]

  • 1. What is the result of calling the append method on a list? 2. What must...

    1. What is the result of calling the append method on a list? 2. What must be defined prior to using a method like append? 3. Explain why two lines caused an IndexError. 4. What is the result of calling the remove method on a list? 5. Give one example of a list method that requires an argument and one that does not. 6. Describe the syntax similarities and differences between using a list method like append and Python built-in...

  • I try to define a PYTHON program that can print the largest factor of the number...

    I try to define a PYTHON program that can print the largest factor of the number except for the number itself. Ex: enter n as 15, the program will print: 5. The factor of 15 is 15, 5, 3, 1, but 15 will not be counted in this case. If enter a prime number, it will print 1. I am not sure what I did wrong here, please point out my mistake and advise how should I improve. def largest_factor(n)...

  • This is a Python question. This is a Python question. This is a Python question. Create...

    This is a Python question. This is a Python question. This is a Python question. Create two Numpy arrays. First, array X of shape 3x4 filled with random normal numbers (see np.randn). Second, array Y of 5x4 filled with consecutive integers starting at zero. Add the two arrays using broadcasting to create an array of shape 3x5x4. You will need to insert an axis of length 1 in the right place to do that. See np.newaxis. Store the result in...

  • Use python to code! Q1 - You need to keep track of book titles. Write code...

    Use python to code! Q1 - You need to keep track of book titles. Write code using function(s) that will allow the user to do the following. 1. Add book titles to the list. 2. Delete book titles anywhere in the list by value. 3. Delete a book by position. Note: if you wish to display the booklist as a vertical number booklist , that is ok (that is also a hint) 4. Insert book titles anywhere in the list....

  • ** Language Used : Python ** PART 2 : Create a list of unique words This...

    ** Language Used : Python ** PART 2 : Create a list of unique words This part of the project involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing. Create a test...

  • Python Help Please Problem 4-4: Make a list of 20 numbers and place them in a...

    Python Help Please Problem 4-4: Make a list of 20 numbers and place them in a random order (don't arrange them in ascending or descending order - make sure the list is truly random). Calculate and print out the largest number in the list and the lowest number in the list. Problem 4-5: Make a list of multiples of 5 between 1 and 100. Once you have your list, print it out. Problem 4-6: Generate a list of values from...

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