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()*...
Create program that sorts words of a string based on first letter of each word. Use...
Create program that sorts words of a string based on first letter of each word. Use C programming language. - Only use stdio.h and string.h - Remove any newline \n from input string - Use insert function - Input prompt should say "Enter string of your choice: " - Output should print sorted string on new line Example:     Enter string of your choice: this is a string     a is string this
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...
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...
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...
** 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...
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...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT