Question

Use the Python programming language to complete below (I need the New Answer for this, and...

Use the Python programming language to complete below (I need the New Answer for this, and please provide the screenshot of the source code. Thank you!):

  • Write a program to input an uncertain string S of words and space/tab
    • Remove space/tab in S
    • Remove identical words
    • Sort all words in the order of a-z
    • Print the output strings
  • Example:
    • Input String: "hello world and practice makes perfect and hello world again"
    • Output String: "again and hello makes perfect practice world"
  • Tips:
    • use set to remove identical words,
    • use sorted() to sort words
    • use split() to remove space

Homework Answers

Answer #1

string =input("Enter a string\n")#Input a string
a_list = string.split()#splitting it into list to remove extra spaces and tabs
new_string = " ".join(a_list)#string without tabs and spaces
l = new_string.split() #Splitting the new string 
k = []
for i in l: #removing identical words
    if (new_string.count(i)>1 and (i not in k)or new_string.count(i)==1): 
        k.append(i) 
new_string=' '.join(k) #new string after removing identical words
st=new_string.split(" ")
st.sort()#sorting in alphabetical order
res=" ".join(st)
print(res)#printinh the final output

Please upvote if this answer is helpful..

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
Use Python: # Problem Set 03: - Write a program to input an uncertain string *S*...
Use Python: # Problem Set 03: - Write a program to input an uncertain string *S* of words and space/tab - Remove space/tab in S - Remove identical words - Sort all words in the order of a-z - Print the output strings - Example: - Input String: "hello world and practice makes perfect and hello world again" - Output String: "again and hello makes perfect practice world" - Tips: - use *set* to remove identical words, - use *sorted()*...
use c language only to solve this porblem -------------------------- Have the function StringChallenge(str) take the str...
use c language only to solve this porblem -------------------------- Have the function StringChallenge(str) take the str string parameter being passed and return the number of words the string contains (e.g. "Never eat shredded wheat or cake" would return 6). Words will be separated by single spaces. Examples Input: "Hello World" Output: 2 Input: "one 22 three" Output: 3 you have the following code what edits can you do #include <stdio.h> #include <string.h> void StringChallenge(char str[]) {      // code goes...
Modify your mapper to count words after removing punctuation marks during mapping. Mapper code below. #!/usr/bin/env...
Modify your mapper to count words after removing punctuation marks during mapping. Mapper code below. #!/usr/bin/env python #the above just indicates to use python to intepret this file #This mapper code will input a line of text and output <word, 1> # import sys sys.path.append('.') for line in sys.stdin: line = line.strip() #trim spaces from beginning and end keys = line.split() #split line by space for key in keys: value = 1 print ("%s\t%d" % (key,value)) #for each word generate...
WRITE USING PYTHON PROGRAMMING THE CODE GIVEN BELOW HAS SOME ERRORS WHICH NEED TO BE SOLVED....
WRITE USING PYTHON PROGRAMMING THE CODE GIVEN BELOW HAS SOME ERRORS WHICH NEED TO BE SOLVED. ALSO THE 2 POINTS MENTIONED BELOW SHOULD BE PRESENT IN THE CODE Write a script that calculates the 3 longest words of a text stored in a file and print them from the longest to the smaller of the 3. Please note: 1. The name of the file is word_list.csv and it doesn’t need to be asked to the user (meaning the name will...
** Language Used : Python ** PART 2 : Create a list of unique words This...
** Language Used : Python ** PART 2 : Create a list of unique words This part of the project involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing. Create a test...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will implement Queue Abstract Data Type with the following functions/methods.  Any build-in/pre-defined Queue function/library (e.g., java.util.Queue in Java) is NOT allowed to use in your code. push(Element):  insert the input Element (e.g., String or Integer in Java) to the end of the queue. pop(): remove the head element of the queue and print the head element on screen. count():  return the total number of elements in the queue...
Here is the code I am supposed to Analyze: // If we want to use the...
Here is the code I am supposed to Analyze: // If we want to use the Scanner class (type) to get user input, we need // to import the following Java package that includes the Scanner class // definitions. We do not have to add an import statement to use the // print() or println() methods of the System object, because they // are built in. import java.util.Scanner; public class PRG420Week1_AnalyzeAssignment { /* The main() method you see below is...
write a code in python Write the following functions below based on their comments. Note Pass...
write a code in python Write the following functions below based on their comments. Note Pass is a key word you can use to have a function the does not do anything. You are only allowed to use what was discussed in the lectures, labs and assignments, and there is no need to import any libraries. #!/usr/bin/python3 #(1 Mark) This function will take in a string of digits and check to see if all the digits in the string are...
Use python language please #One of the early common methods for encrypting text was the #Playfair...
Use python language please #One of the early common methods for encrypting text was the #Playfair cipher. You can read more about the Playfair cipher #here: https://en.wikipedia.org/wiki/Playfair_cipher # #The Playfair cipher starts with a 5x5 matrix of letters, #such as this one: # # D A V I O # Y N E R B # C F G H K # L M P Q S # T U W X Z # #To fit the 26-letter alphabet into...
Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT