belongs to collection: Python String Exercises
Given string contains a combination of the lower and upper case letters. Write a program to arrange the characters of a string so that all lowercase letters should come first.
Given:
str1 = PyNaTive
Expected Output:
yaivePNT
Hint:
Iterate each character from a string and check if the current character is the lower or upper case using islower() string function
islower()
Solution:
join()
str1 = "PYnAtivE" print('Original String:', str1) lower = [] upper = [] for char in str1: if char.islower(): # add lowercase characters to lower list lower.append(char) else: # add uppercase characters to lower list upper.append(char) # Join both list sorted_str = ''.join(lower + upper) print('Result:', sorted_str)
Explanation:
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Hint:
Iterate each character from a string and check if the current character is the lower or upper case using
islower()
string functionSolution:
islower()
string function.join()
function.Explanation:
need an explanation for this answer? contact us directly to get an explanation for this answer