Question
Exercise-1: Make a list that includes four careers, such as 'programmer', 'truck driver', etc Use the list.index() function to find the index of a career
Exercise-1: Make a list that includes four careers, such as 'programmer', 'truck driver', etc Use the list.index() function to find the index of a career in your list. Use the in function to show that this career is in your list. Use the append() function to add a new career to your list. Use the insert() function to add a new career at the beginning of the list. Use a loop to show all the careers in your list.
Exercise-2: Write a function called is_sorted that takes a list as a parameter and returns True if the list is sorted in ascending order and False otherwise. You can assume (as a precondition) that the elements of the list can be compared with the relational operators <, >, etc. For example, is_sorted([1,2,2]) should return True and is_sorted(['b','a']) should return False.
Exercise-3: Write a function called remove_duplicates that takes a list and returns a new list with only the unique elements from the original. Hint: they dont have to be in the same order.
Exercise-4: Make a list of the first ten multiples of ten (10, 20, 30... 90, 100). There are a number of ways to do this, but try to do it using a list comprehension. Print out your list.
Exercise 5: Write a function called Chop that takes a list and returns a new list that contains all but the first and last elements. Name: Chop Argument: List Return: List
Here is an example of how to use (or test) the function: a = [a,b,c,d,e] b = Chop(a) print b # prints [b,c,d]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started