python - How to separate upper and lower case letters in a string -


i have written code separates characters @ 'even' , 'odd' indices, , modify separates characters upper/lower case. can't figure out how string such "abbzxyp". have tried using .lower , .upper think i'm using them incorrectly.

def upperlower(string):     odds=""     evens=""     index in range(len(string)):         if index % 2 == 0:             evens = evens + string[index]         if not (index % 2 == 0):             odds = odds + string[index]     print "odds: ", odds     print "evens: ", evens 

are looking 2 strings, 1 uppercase letters , lowercase letters? below function return 2 strings, upper lowercase:

def split_upper_lower(input):     upper = ''.join([x x in input if x.isupper()])     lower = ''.join([x x in input if x.islower()])      return upper, lower 

you can call following:

upper, lower = split_upper_lower('abbzxyp') 

which gives 2 variables, upper , lower. use them necessary.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -