0
How do i split
how do i split DoYourHomework to Do Your Homework
5 Réponses
+ 1
List comprehension. It's basically a collapsed loop. I couldn't find any examples online (and I'm new to Python) so please excuse it if messy/bad vs RegEx.
>>> a="DoYourHomework"
>>> "".join([" "+z if z.isupper() else z for z in list(a)]).strip()
'Do Your Homework'
By the way, for ASCII: bit 6 is 0 in uppercase, 1 in lowercase if someone thinks that's useful.
0
string.split() function will not work in this case because of zero-width match. use regular expressions instead:
import re
str = 'DoYourHomework'
lst = re.findall('[A-Z][^A-Z]*', str)
print (lst)
0
is there any other way?
0
maybe there is, but this one seems to be very simple and convenient.
you can, of course, search through the string in loop, check if letter is capital etc., but that's not a good strategy.
0
i was just wondering because i havent learned about regular expressions so i dont know all the applications it carries