Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 5, Problem 7TF
Program Description Answer
The split method is used to break a string into list of substrings whereas join method joins the list of substrings into a single string.
Hence, the given statement is “True”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Odd Even Number Using List
CLOSE
START
Tags: List iterator
Write a java program that read list of integer numbers from input user. If the number is even add it into evenList.
Otherwise add to odd List.
At the end of the code, display the elements of the odd and even numbers list respectively with ascending order.
Display your output in the following format:
():
[Note: The code must use list and iterator]
Input:
230-15 8 22-11 6-7 18
Output:
Odd List (4): -15-11-73
Even List (6): 0 2 6 8 18 22
Split - Filter - Sort
romeo = 'But soft what light through
yonder window breaks It is the east and
Juliet is the sun Arise fair sun and kill the
envious moon Who is already sick and
pale with grief
Split the long string romeo into a list of
words using the split function. For each
word, check to see if the word is already in
a list. If the word is not in the list, add it to
the list. When the program completes, sort
and print the resulting words in
alphabetical order.
The result will be like this:
['Arise', 'But', 'It', 'Juliet', "Who', 'already',
'and', 'breaks', 'east', 'envious', 'fair', 'grief',
'is', 'kill', "'ight', 'moon', 'pale', 'sick', 'soft',
'sun', 'the', 'through', 'what', 'window', 'with',
'yonder']
def q5(sentence):
Assumes sentence is a string.
Returns a list of all the words in sentence, where a word is a token
separated by white space, (you can use sentence.split()), and then
for each word, make it lowercase and remove any character that is not
alpha-numeric (a-z or 8-9).
For example,
I
q5("The Plague" (French: "La Peste"), 1947, by Albert CamUs.')
should return ['the', 'plague', 'french', 'la', 'peste', '1947', 'by', 'albert', 'camus']
q5('Red@Dragon....ca is great!')
should return ['reddragonca', 'is', 'great']
pass
Chapter 5 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
Ch. 5 - Prob. 1TFCh. 5 - Prob. 2TFCh. 5 - Prob. 3TFCh. 5 - Prob. 4TFCh. 5 - Prob. 5TFCh. 5 - Prob. 6TFCh. 5 - Prob. 7TFCh. 5 - Prob. 8TFCh. 5 - Prob. 9TFCh. 5 - Prob. 10TF
Ch. 5 - Prob. 1MCCh. 5 - Prob. 2MCCh. 5 - Prob. 3MCCh. 5 - Prob. 4MCCh. 5 - Prob. 5MCCh. 5 - Prob. 6MCCh. 5 - Prob. 7MCCh. 5 - Prob. 8MCCh. 5 - Prob. 9MCCh. 5 - Prob. 10MCCh. 5 - Prob. 1DCh. 5 - Prob. 2DCh. 5 - Prob. 3DCh. 5 - Prob. 4DCh. 5 - Prob. 5DCh. 5 - Prob. 1PECh. 5 - Prob. 2PECh. 5 - Prob. 3PECh. 5 - Prob. 4PECh. 5 - Prob. 5PECh. 5 - Prob. 6PECh. 5 - Prob. 7PECh. 5 - Prob. 8PECh. 5 - Prob. 9PECh. 5 - Prob. 10PECh. 5 - Prob. 11PECh. 5 - Prob. 12PECh. 5 - Prob. 13PECh. 5 - Prob. 14PECh. 5 - Prob. 15PECh. 5 - Prob. 16PE
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- WAP c# program creates a string, s1, which deliberately leaves space for a name, much like you’d do with a letter you plan to run through a mail merge. We add two to the position where we find the comma to make sure there is a space between the comma and the name.arrow_forwardContact list: Binary Search A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings). That list is followed by a name, and your program should output the phone number associated with that name. Define and call the following function. The return value of FindContact is the index of the contact with the provided contact name. If the name is not found, the function should return -1 This function should use binary search. Modify the algorithm to output the count of how many comparisons using == with the contactName were performed during the search, before it returns the index (or -1). int FindContact(ContactInfo contacts[], int size, string contactName) Ex: If the input is: 3 Frank 867-5309 Joe 123-5432 Linda…arrow_forwardLab Goal : This lab was designed to teach you more about list processing and algorithms.Lab Description : Write a program that will search a list to find the first odd number. If an odd number is found, then find the first even number following the odd number. Return the distance between the first odd number and the LAST even number. Return -1 if no odd numbers are found or there are no even numbers following an odd numberarrow_forward
- Counting hashtags Write Python code to count the frequency of hashtags in a twitter feed. Your code assumes a twitter feed variable tweets exists, which is a list of strings containing tweets. Each element of this list is a single tweet, stored as a string. For example, tweets may look like: tweets = ["Happy #IlliniFriday!", "It is a pretty campus, isn't it, #illini?", "Diving into the last weekend of winter break like... #ILLINI #JoinTheFight", "Are you wearing your Orange and Blue today, #Illini Nation?"] Your code should produce a sorted list of tuples stored in hashtag_counts, where each tuple looks like (hashtag, count), hashtag is a string and count is an integer. The list should be sorted by count in descending order, and if there are hashtags with identical counts, these should be sorted alphabetically, in ascending order, by hashtag. From the above example, our unsorted hashtag_counts might look like: [('#illini', 2), ('#jointhefight', 1),…arrow_forwardzeroTriples.py: Write a program that reads a list of integers from the user, until they enter -12345 (the -12345 should not be considered part of the list). Then find all triples in the list that sum to zero. You can assume the list won’t contain any duplicates, and a triple should not use the same number more than once. For example:$ python3 zeroTriples.py124-123450 triples found $ python3 zeroTriples.py-3142-123451 triple found:1, 2, -3 $ python zeroTriples.py-91-3245-4-1-123454 triples found:-9, 4, 51, -3, 2-3, 4, -15, -4, -1arrow_forwardComplete the following list comprehensionlc5 = [ for c in 'bu be you']so that it produces the list [True, True, False, True, False, False, False, False, True]. Note that the expression 'bu be you' is a string, not a list.arrow_forward
- Write in Java pleasearrow_forwardcheck_equivalency(tokens): Takes a list as input. Returns True if the list contains three elements, the second element is an equals sign ('='), and the first and third elements are equal to each other. Returns False otherwise.arrow_forwardWhat are some of the similarities between string and lists?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT