Question

In: Computer Science

1. Find and print the length of the list listTest. 2. We can test if an...

1. Find and print the length of the list listTest.

2. We can test if an item exists in a list or not, using the keyword in

It will give you a boolean response if a certain element is present. Find whether 'p' or 'P' is present in listTest, and print the results.

Print results first for 'p' and then for 'P' as shown in example below.

For example:

Test Result
listTest=['c','i','s','c','1','0','6','P','y','t','h','o','n']
False
True

3. We can delete one or more items from a list using the keyword del. It can even delete the list entirely.

From the list listTest, delete the 4th element.

4. Using the del keyword and/or the slicing operator :, delete the 3rd to 6th elements from the list listTest.

5. We can access a range of items in a list by using the slicing (colon) operator.

There is a predefined list listTest. Use the slicing operator to print the third to fifth elements from listTest as a list.

Note: this does not mean the values at indices 3, 4, and 5!

6. We can access a range of items in a list by using the slicing operator (colon).

7. There is a predefined list listTest. Use the slicing operator to print the elements (as a list) from beginning through the sixth from listTestWe can access a range of items in a list by using the slicing operator (colon).

Given a predefined list listTest, use slicing to print the elements from the fourth through the end from listTest

Solutions

Expert Solution

listTest=["C","i","s","c","1","0","6","P","y","t","o","n"]#defining a list
# 1.legth of list
print("1.Legth of list = ",len(listTest))#len operator is used to find length of list

# 2.using keyword in
print("2.")
if 'p' in listTest:
print("True")
else:
print("False")
if 'P' in listTest:
print("True")
else:
print("False")

# 3.deleting 4th element
del(listTest[3]) #list index is starts from 0.so here 3 means 4th element
print("3.After deleting 4th element:\n",listTest)

# 4.deleting 3 to 6 elements
del(listTest[2:6])#[2:6] means 3rd,4th,5th,6th elements
print("4.After deleting 3 to 6 elements:\n",listTest)

# 5.prints 3 to 5 elements from listTest as list
list1=listTest[2:5] #[2:5] means 3rd,4th,5th elements
print("5.prints 3 to 5 elements:\n",list1)

# 6.accessing rage of items in listTest
print("6.accessing 1 to 4 elements:\n",listTest[:4])#[:4] means 1st,2nd,3rd,4th elements

# 7.
print("7.")
print("Beginning through the sixth:\n",listTest[:6]) # [:6] means 1st element to 6th element
print("fourth through the end:\n",listTest[3:]) # [3:] means 4th element to last element


Related Solutions

11. Print the length of the new list out to the screen. Ensure the new list...
11. Print the length of the new list out to the screen. Ensure the new list has a length of 25. 12. Append the integer value 42 to the new list. Print the new list to the screen.   13. Permanently sort the new list. Print the new list to the screen. 14. Remove the integer value 42 from the new list. Print the new list to the screen. 15. Implement a for loop to iterate through the new list. For...
Hello, ***We have to print the second list backward while interleaved with the first list in...
Hello, ***We have to print the second list backward while interleaved with the first list in normal order.*** its PYTHON language. Please refer the below example. Bold are the inputs that the user enters. In here the user input words and much as he wants and when he enter STOP, it stops and he is asked to enter more words.(second words count equals to the word count he inputs in the first phase) Enter words, STOP to stop. Ok Enter...
1. can we be fat and still be healthy? 2. State why/why not 3. Find at...
1. can we be fat and still be healthy? 2. State why/why not 3. Find at least ONE academically credible source to support your opinion AND provide a brief summary of that article.
1.Find the equation of the tangent to x=t^2-t, y=t^2+t+1, at the point t=1 2.Find the length...
1.Find the equation of the tangent to x=t^2-t, y=t^2+t+1, at the point t=1 2.Find the length of the curve x=t*sint, y=t*cost, 0≤t≤1
import random #the menu function def menu(list, question): for entry in list: print(1 + list.index(entry),end="") print(")...
import random #the menu function def menu(list, question): for entry in list: print(1 + list.index(entry),end="") print(") " + entry) return int(input(question)) plz explain this code
Implement a non-recursive reverse print of linked list using stack and the main function to test:...
Implement a non-recursive reverse print of linked list using stack and the main function to test: You will need to finish the printReversed_nonrecursive method in ch04.LinkedStack2 class, and the ch04.UseStack2 is the main function to test. public class LinkedStack2<T> extends LinkedStack<T> { private void revPrint(LLNode<T> listRef) { if (listRef != null) { revPrint(listRef.getLink()); System.out.println(" " + listRef.getInfo()); } } public void printReversed() { revPrint(top); } /* use stack to implement non-recursive reverse print */ public void printReversed_nonrecursive() { } public...
Prove series 2, (-1/2), (2/9), (-1/8) is convergent by the alternating series test and find the...
Prove series 2, (-1/2), (2/9), (-1/8) is convergent by the alternating series test and find the number of terms required to estimate the sum of the series with an error of less than 0.05
List the ways that we evaluate (test methods) platelets in the lab. Just a simple list...
List the ways that we evaluate (test methods) platelets in the lab. Just a simple list at this point.
the language is matlab 1) Write a code that will print a list consisting of “triangle,”...
the language is matlab 1) Write a code that will print a list consisting of “triangle,” “circle,” and “square.” It prompts the user to choose one, and then prompts the user for the appropriate quantities (e.g., the radius of the circle) and then prints its area. If the user enters an invalid choice, the script simply prints an error message. For calculating the area, create separate functions for each choice. Name them as calcTriangle, calcCircle, calcSquare respectively, which are only...
What can we find out by conducting the Vertical Analysis of the Income Statement? 1. We...
What can we find out by conducting the Vertical Analysis of the Income Statement? 1. We can find out whether individual expenses are growing per unit sales over time. 2. We can find out whether the amounts of individual expenses are growing over time. 3. We can find out how fast revenues are growing over time. 4. We can find out growth rate of net profit of each year against the previous year. Which of the following describes the Retained...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT