Question

In: Computer Science

Python 1. Change the order of an input string based on Unicode equivalent. Write a function...

Python

1. Change the order of an input string based on Unicode equivalent.

Write a function Reorder that will take an input string of a maximum length of 20 characters and create a new string that reorders the string based on it’s binary Unicode character equivalent, e.g. ‘a’ = 0x61, ‘A’ = 0x41, from smallest value to largest value. In this example, ‘A’ would come before ‘a’, as 0x41 is a smaller number than ox61. Note, use python logical operators to do the comparison. Do not try to create a Unicode lookup table. For your code, use the string “sum=(x*259)/average” as your input string to your function.

Solutions

Expert Solution

Python Code:

#Function to sort the string
def sortChar(stringinp):
#Declare and initialize sorted string with first character of input string. We can compare with this later


sortedString = stringinp[0]
#Loop through input string
for ch in stringinp[1:]:


#Loop through the sorted string
for i in range(0,len(sortedString)):


#Comparing the unicode charater value of characters of 2 strings. If value is lower, then insert the character in before the larger character
if hex(ord(ch)) < hex(ord(sortedString[i])):


sortedString = sortedString[0:i] + ch + sortedString[i:]
break


else:


#If it is the largest character encountered append it at the end
sortedString = sortedString + ch


#Print the sorte string
print(f'Sorted string is {sortedString}')


  
sortChar('sum=(x*259)/average')

Sample Output:

Sorted string is ()*/259=aaeegmrsuvx

#Function to sort the string def sortChar(stringinp): #Declare and initialize sorted string with first character of input string. We can compare with this later sortedString = stringinp[0] #Loop through input string for ch in stringinp[1:]: #Loop through the sorted string for i in range(0, len(sortedString)): #Comparing the unicode charater value of characters of 2 strings. If value is lower, then insert the character in before the larger character if hex(ord(ch)) < hex(ord(sortedString[i])): sortedString = sortedString[0:1] + ch + sortedString[i:] break else: #If it is the largest character encountered append it at the end sortedString = sortedString + ch #Print the sorte string print('Sorted string is sortedString}') sortCharl'sum=(x*259)/average') ||


Related Solutions

In Python Write a function to read a Sudoku board from an input string. The input...
In Python Write a function to read a Sudoku board from an input string. The input string must be exactly 81 characters long (plus the terminating null that marks the end of the string) and contains digits and dots (the `.` character represents an unmarked position). The input contains all 9 rows packed together. For example, a Sudoku board that looks like this: ``` ..7 ... ... 6.4 ... ..3 ... .54 ..2 ... .4. ... 9.. ... ..5 385...
In python write a function whose input is a string. This function determines the data type...
In python write a function whose input is a string. This function determines the data type of the input string. The data types can be a float, int, or string. Most pass the following assertions: assert determine_data_type('1.2') == float assert determine_data_type('4') == int assert determine_data_type('EAS503') == str
Python Write a program that will analyse the string input and print “accept” or “reject” based...
Python Write a program that will analyse the string input and print “accept” or “reject” based on the pattern given Accept if it fulfils the following conditions -String length 9 -3 small alphabet (3 lowercase letter) -3 digits -3 big alphabet (3 uppercase letters) -1st alphabet should be a capital -Last alphabet should be a number -Two consecutive alphabets can't be small Reject if any of the conditions is absent So i want it to accept or reject my input,...
Use python write a function that translates the input string into Pig Latin. The translation should...
Use python write a function that translates the input string into Pig Latin. The translation should be done word by word, where all words will be separated by only one space. You may assume that each word must have at least one vowel (a,e,i,o,u and uppercased counterparts), and there will be no punctuation or other special characters in the input string. The Pig Latin rules are as follows: For words that begin with consonants, all letters before the initial vowel...
Using Python Question 1 Write an input function. Then use it to supply the input to...
Using Python Question 1 Write an input function. Then use it to supply the input to following additional functions: i) Print multiplication table of the number from 1 to 12. ii) Print the sum of all the numbers from 1 to up the number given. iii) Print if the number supplied is odd or even. Question 2 Write function that asks for input from a user. If the user types 'end', the program exits, otherwise it just keeps going.
Python Program 1: Write a program that takes user input in the form of a string...
Python Program 1: Write a program that takes user input in the form of a string Break up the string into a list of characters Store the characters in a dictionary The key of the dictionary is the character The value of the dictionary is the count of times the letter appears Hint: remember to initialize each key before using Output of program is the count of each character/letter Sort the output by key (which is the character) Python Program...
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
Write a function that takes a C string as an input parameter and reverses the string.
in c++ Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the...
Write a Python function that takes a list of string as arguments. When the function is...
Write a Python function that takes a list of string as arguments. When the function is called it should ask the user to make a selection from the options listed in the given list. The it should get input from the user. Place " >" in front of user input. if the user doesn't input one of the given choices, then the program should repeatedly ask the user to pick from the list. Finally, the function should return the word...
python 3 please Define a function voweliest that takes as input a string and returns as...
python 3 please Define a function voweliest that takes as input a string and returns as output a tuple where the string that has the most vowels in it is the first element and the second is the number of vowels in that string. Note: don't worry about ties or capital letters Hint: consider defining and using a separate function that counts the number of vowels in a given string
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT