How to move all uppercase characters to the beginning of string in Python

1 Answer

0 votes
def move_uppercase_to_beginning(s):
  s_len = len(s)
  lowercase = ""
  uppercase = ""

  for i in range(0, s_len, 1):
    ch = s[i]
    if (ch >= 'A' and ch <= 'Z'): 
      uppercase += ch 
    else: 
      lowercase += ch
  
  return uppercase + lowercase



s = "Python C++ PHP Java" 

print(move_uppercase_to_beginning(s))



'''
run:

PCPHPJython ++  ava

'''

 



answered Aug 20, 2019 by avibootz

Related questions

...