
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Answer number 2 please
![2. Write a function string_to_list that takes a sequcnce of integer numbers as a string (see
the examples below) and returns a list containing that sequence of numbers.
For example, string_to_list('1, 4, 9, 16, 25, 36') should return the list
[1, 4, 9, 16, 25, 36] , and string_to_list('1, -1, 1, -1') should return the list
[1, -1, 1, -1] .
You should assume that your input string is formatted eractly as in the eramples above (i.e.,
with each nuTmber separated by a comma and space). You may find the split method helpful.
3. Write a function restrict type that takes any list 1st and typet (recall some of the
types we have seen so far in the class are int, float, str, bool, and list ), and that
returns a new list consisting only of those elements from 1st that are of type t.
For example, if 1st2
["pizza", 5, True, -3.14, "hello", False, 0] , then
restrict type (1st2, int) should return the list [5, 0], and restricttype (1st2, bool)
should return the list [True, False]
Hint: Recall the built-in function type returns the type name of a given value.
4. Write a function remove negative that takes any list of mumbers num lst and returns the
same list, cxcept all the negative nimbers in the list have been removed.
For example, if 1st = [-4, -5, 1, 6, 2, -7, 5], then remove_negative (1st) should
return the list [1, 6, 2, 5], and 1st itself should now have the value [1, 6, 2, 5]
1lint: Instead of tracersing through num lst
you may find it helpful to traeerse through a
Copy of num_lst](https://content.bartleby.com/qna-images/question/5f674f25-25cd-4157-a3b0-b4cefdd441a9/6125cb1b-f66a-467b-9827-bddf238f4c0c/opv0oi_thumbnail.jpeg)
Transcribed Image Text:2. Write a function string_to_list that takes a sequcnce of integer numbers as a string (see
the examples below) and returns a list containing that sequence of numbers.
For example, string_to_list('1, 4, 9, 16, 25, 36') should return the list
[1, 4, 9, 16, 25, 36] , and string_to_list('1, -1, 1, -1') should return the list
[1, -1, 1, -1] .
You should assume that your input string is formatted eractly as in the eramples above (i.e.,
with each nuTmber separated by a comma and space). You may find the split method helpful.
3. Write a function restrict type that takes any list 1st and typet (recall some of the
types we have seen so far in the class are int, float, str, bool, and list ), and that
returns a new list consisting only of those elements from 1st that are of type t.
For example, if 1st2
["pizza", 5, True, -3.14, "hello", False, 0] , then
restrict type (1st2, int) should return the list [5, 0], and restricttype (1st2, bool)
should return the list [True, False]
Hint: Recall the built-in function type returns the type name of a given value.
4. Write a function remove negative that takes any list of mumbers num lst and returns the
same list, cxcept all the negative nimbers in the list have been removed.
For example, if 1st = [-4, -5, 1, 6, 2, -7, 5], then remove_negative (1st) should
return the list [1, 6, 2, 5], and 1st itself should now have the value [1, 6, 2, 5]
1lint: Instead of tracersing through num lst
you may find it helpful to traeerse through a
Copy of num_lst
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images

Knowledge Booster
Similar questions
- Convert the following decimal number to binary: 21.625 Question 12 options: A. 10101.110 B. 10101.011 C. 10010.011 D. 10010.101 E. 10101.101arrow_forwardQuestion 1 Is the following a prefix code? b. d e f to 01 10 101 1010 00 1arrow_forwardHow are the continue and break lines different?arrow_forward
- In which numbering system are all numeric values represented as a sequence of 0s and 1s? What numbering system is used to represent all numeric values?arrow_forwardWhich of the following is a Dword? fe de fe af 12 0001 0101 1010 0111 112arrow_forwardWhich of the following symbol is used in relative cell renference Select one: a. = b. * c. + d. None of the given choices are correctarrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY