Question

(Python) ######new part: append method ######we have a list ##lis = [1,'a',8, 0] ##print(lis) ########to append...

(Python)

######new part: append method
######we have a list
##lis = [1,'a',8, 0]
##print(lis)
########to append "yes" to the list:
##lis.append('yes')
##print(lis)
########index method: let us find the index of 'yes':
##index_yes = lis.index('yes')
##print(index_yes) ## here you cam see that it is 4, as it must be
########insert method: we want to put 'o, no!' in the list at the first place:
##lis.insert(0, 'o,no!')
##print(lis)
########### sort method: we wnat to sort out list; for our regrets sorting is
###########possible only for same kind of data: list must be all numeric of
##########string.
##########We split our list for string part (lis_str) and numeric part (lis_num):
##########here is our list now: lis = ['o,no!', 1, 'a', 8, 0, 'yes']
######### numeric items have indeces 1,3,4, string items: 0,2,5.
##num = [1,3,4]
##stri = [0,2,5]
#########let us use the trick:
##lis_num = [lis[i] for i in num]
##lis_stri = [lis[i] for i in stri]
#########checking:
##print(lis_num)
##print(lis_stri)
#########let us sort them:
##lis_num.sort()
##lis_stri.sort()
#########cheking:
##print(lis_num)
##print(lis_stri)
######################TASK 2. For the list liss do the following:
##liss = ['o,no!', -1, 'why?', 8, 0, 'yes', 'not, really']
#####append "hi" to the end
#####find the index of "yes" in the new liss list
#####insert 'what?' to the third place
#####extract string part of the liss and sort it
####$$$$$$$$ If your code works - it is acceptable, if it does not - it is not acceptable.

#########remove and del
######## let us get the list
##li = [1, 2, 6, 'yes']
##########we want to remove the item 2:
##li.remove(2)
##print(li)
###########we want to delete the element with index 2 from the new list li:
##del li[2]
##print(li)

Homework Answers

Answer #1

If you have any doubts, please give me comment...

####new part: append method

####we have a list

lis = [1,'a',8, 0]

print(lis)

######to append "yes" to the list:

lis.append('yes')

print(lis)

######index method: let us find the index of 'yes':

index_yes = lis.index('yes')

print(index_yes) ## here you cam see that it is 4, as it must be

######insert method: we want to put 'o, no!' in the list at the first place:

lis.insert(0, 'o,no!')

print(lis)

######### sort method: we wnat to sort out list; for our regrets sorting is

#########possible only for same kind of data: list must be all numeric of

########string.

########We split our list for string part (lis_str) and numeric part (lis_num):

########here is our list now: lis = ['o,no!', 1, 'a', 8, 0, 'yes']

####### numeric items have indeces 1,3,4, string items: 0,2,5.

num = [1,3,4]

stri = [0,2,5]

#######let us use the trick:

lis_num = [lis[i] for i in num]

lis_stri = [lis[i] for i in stri]

#######checking:

print(lis_num)

print(lis_stri)

#######let us sort them:

lis_num.sort()

lis_stri.sort()

#######cheking:

print(lis_num)

print(lis_stri)

####################TASK 2. For the list liss do the following:

liss = ['o,no!', -1, 'why?', 8, 0, 'yes', 'not, really']

###append "hi" to the end

liss.append("hi")

print(liss)

###find the index of "yes" in the new liss list

index_hi = liss.index("yes")

print(index_hi)

###insert 'what?' to the third place

liss.insert(2, 'what?')

print(liss)

###extract string part of the liss and sort it

liss_str = [el for el in liss if type(el) is str]

liss_str.sort()

print(liss_str)

##$$$$$$$$ If your code works - it is acceptable, if it does not - it is not acceptable.

#######remove and del

###### let us get the list

li = [1, 2, 6, 'yes']

########we want to remove the item 2:

li.remove(2)

print(li)

#########we want to delete the element with index 2 from the new list li:

del li[2]

print(li)

Know the answer?
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
Similar Questions
(Python) For the list liss do the following: ##liss = ['o,no!', -1, 'why?', 8, 0, 'yes',...
(Python) For the list liss do the following: ##liss = ['o,no!', -1, 'why?', 8, 0, 'yes', 'not, really'] #####append "hi" to the end #####find the index of "yes" in the new liss list #####insert 'what?' to the third place #####extract string part of the liss and sort it ####$$$$$$$$ If your code works - it is acceptable, if it does not - it is not acceptable. #########remove and del ######## let us get the list ##li = [1, 2, 6,...
1. What will the following python code display? num = list(range(5)) print(num) 2. Answer the following...
1. What will the following python code display? num = list(range(5)) print(num) 2. Answer the following questions using the list below. You can record your answers in the essay textbox. data = [5,3,7] A. Write code to replace the value in the 0 position with the number 8. B. Add the value 10 to the end of the list. C. Insert the value 22 after position 1 in the list. D. Remove the value at position 2. E. Sort the...
convert this code to accept int value instead of float values using python. Make sure to...
convert this code to accept int value instead of float values using python. Make sure to follow the same code. do not change the steps and make sure to point to what code you replaced. make sure to have 2 files Method:----------------------- #define a python user difined method def get_float_val (prompt): is_num = False str_val = input (prompt) #prming read for our while #while is_num == False: (ignore this but it works) old school while not is_num: try: value =...
Write an append function void append(const arrayListType<elemType>& otherList) that will take an array list as a...
Write an append function void append(const arrayListType<elemType>& otherList) that will take an array list as a parameter and append it to the current list. Write an operator+ function that will create a new list containing the contents of the two lists added. arrayListType<elemType> operator+(const arrayListType<elemType> & rhs) const so that you can write code like a = b + c where a b and c are all arrayListTypes. Add your functions to the template and write a main program to...
Implement Doubly Linked List get method which behaves like the operator[] of array. - It takes...
Implement Doubly Linked List get method which behaves like the operator[] of array. - It takes an integer parameter i as the index, it throw an Exception if the index i is illegal, returns the element at given index i, it traverse from the header of the list if index i is in the lower end of the list(less than half of the size), and traverse from the trailer of the list if index i is in the higher end...
This must be answered not advance methods, focusing on String method. We are working on Ch...
This must be answered not advance methods, focusing on String method. We are working on Ch 9 in Think Java 1st Ed.I need the program to be bare bones and the coding need to be done the long way with no advanced code. in this lab you will have two methods with headings: - public static int countNumberSigns(String tweetText) - public static int countHashtags(String tweetText) 'String tweetText' means the method is expectiong a string value as an input to it....
Write a program in python that reads in the file quiztext (txt) and creates a list...
Write a program in python that reads in the file quiztext (txt) and creates a list of each unique word used in the file, then prints the list. Generate a report that lists each individual word followed by the number of times it appears in the text, for example: Frequency_list = [('was', 3), ('bird',5), ('it', 27)….] and so on. Note: Notice the structure: a list of tuples. If you're really feeling daring, Google how to sort this new list based...
Assignment 2 Programming Language: Python 2 Preface: Create a new python file with a name of...
Assignment 2 Programming Language: Python 2 Preface: Create a new python file with a name of your choosing (ex: “assignment2.py”). At the top of the file paste the following: import numpy as np import random class Base_Obstacle_Map(object):     def __init__(self, length, width):         self.map = np.zeros((length, width), dtype=np.uint8)     def add_obstacle(self, x, y):         self.map[x, y] = 1     def remove_obstacle(self, x, y):         self.map[x, y] = 0     def display_map(self):         try:             import matplotlib.pyplot as plt             plt.imshow(self.map)...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT