Provide Python code that does the following:
lst1 = ["apple", "banana", "pear", "grapefruit", "pineapple", "grape", "guava", "plum", "peach"]
Write code that then does the following:
Parts A- E should work for a list with any number of elements. You can assume the list will have at least 6 elements.
SOURCE CODE:
*Please follow the comments to better understand the code.
**Please look at the Screenshot below and use this code to copy-paste.
***The code in the below screenshot is neatly indented for better understanding.
# Create the list
lst1 = ["apple", "banana", "pear", "grapefruit", "pineapple", "grape", "guava", "plum", "peach"]
# a. get last item by -1 index
print("The Last Item is: ", lst1[-1])
# b. first item as 0th index
print("the First Item is: ", lst1[0])
# c. all but last three is [0:-3]
print("All But Last Three are: ", lst1[0:-3])
# d. print odd indices using step 2 i.e., lst1[0::2]
print("The Odd Indices are: ", lst1[0::2])
# e. print the even indices using step 2 i.e, lst1[1::2] { start with index-1}
print("The Even Indices are: ", lst1[1::2])
===========
SCREENSHOT:
![list.py # Create the list Isti = [apple, banana, pear, grapefruit, pineapple, grape, guava, plum, peach] #](http://img.homeworklib.com/questions/620ac300-d28d-11ea-b873-83e9f2efe218.png?x-oss-process=image/resize,w_560)
OUTPUT:
The Last Item is: peach
the First Item is: apple
All But Last Three are: ['apple', 'banana', 'pear', 'grapefruit',
'pineapple', 'grape']
The Odd Indices are: ['apple', 'pear', 'pineapple', 'guava',
'peach']
The Even Indices are: ['banana', 'grapefruit', 'grape',
'plum']
=================
Provide Python code that does the following: Create the following list in your program: lst1 =...
In Python 3 only please. A simple function that will be used on
a file.
commonpair(str) – Takes a single string
argument, representing the first word. This function should return
the word that most frequently followed the given argument word (or
one of, in case of ties). If the argument word does not appear in
the text at all, or is never followed by another word (i.e., is the
last word in the file), this function should return None.
I...
Please do the following project in C++ programming
language.
You can use a bag to create a spell checker. The bag serves as a
dictionary and contains a collection of correctly of correctly
spelled workds. To see whether a word is spelled correctly, you see
whether it is contained in the dictionary. Use this scheme to
create a spell checker for the words in an external file. To
simplify your task, restrict your dictionary to a manageable
size.
The dictionary...
IN PYTHON You are building a program for a Point of Sale (POS) machine for a fruit store. The inventory and price list are stored in a file (i.e. items.txt) with an example as follows: banana 3 1.25 apple 6 1.75 orange 32 0.5 pear 55 2.5 For illustration, the first line implies that "There are 3 bananas in the inventory and the price of a banana is $1.25" You have to write four functions: 1. The first function readstockprice...
Write a Python program (remove_first_char.py) that removes the first character from each item in a list of words. Sometimes, we come across an issue in which we require to delete the first character from each string, that we might have added by mistake and we need to extend this to the whole list. Having shorthands (like this program) to perform this particular job is always a plus. Your program should contain two functions: (1) remove_first(list): This function takes in a...
Write a program that does the following in Python Code: Write a new Class called Famous_Day_Born which is a subclass of Famous_Person. Add a method to calculate the day of the week the person was born and print out all of the corresponding information using the overridden print method. Use the following code below as a starting point. ////////////////////////////////////////////////////// from datetime import datetime class Famous_Person(object): def __init__(self, last, first, month,day, year): self.last = last self.first = first self.month = month...
Write a program that does the following in Python Code: Stores the following three lists: last_name = ["Smith", "Jones", "Williams", "Bailey", "Rogers", "Pyle", "Rossington"] first_name =["Lisa", "Bill", "Jay", "Sally", "Walter","Jake","Gary"] phone_number =["240-233-1921", "301-394-2745", "571-321-8934", "703-238-3432", "703-947-9987", "301-945-3593", "240-671-3221"] Has a function named combine_lists() that takes in last_names, first_names and phone_numbers as lists and returns a dictionary called phone_book that uses last_name as the key and a list consisting of first_name and phone_number. Has a main function that iterates through the...
1) Which of the following is NOT true about a Python
variable?
a) A Python variable must have a value
b) A Python variable can be deleted
c) The lifetime of a Python variable is the whole duration of a
program execution.
d) A Python variable can have the value
None.
2) Given the code segment:
What is the result of executing the code segment?
a) Syntax error
b) Runtime error
c) No error
d) Logic error
3) What...
Python code
You will need to make use of the random library for this homework. It is pretty simple to use. You can use the following methods: random.choice(list) returns a single item from the list, tuple or string at random. random.sample(list.o - returns a new list of n items randomly chosen from the list, tuple or string random shufflellist)randomly reorders all of the items in the list and changes the list itself. The list must be a mutable object so...
PYTHON LANGUAGE Task 11 -Create a list with 5 items having 3 distinct data types -output the second element of the list -output the last element of the list using -negative index -positive index -len method Task 12 -Create a list with 3 items -add an item to the end of the list -remove the first item of the list -determine if an item exists in the list -if it does, display its index -if it does not, give user...
Create a Python list (use first three letters of your name followed by the letter L as the name of the list.) with the following data: 10, 20.0, 50.00, 7000, 7500, 7700, 7800, 8000, 9000, ‘python’. Display the entire list with an appropriate message. Display the 4th element in the list with an appropriate message. Display the first 3 values of the list only. Display all the values starting from the sixth element to the end of the list. Change...