0
How the string capitalize ?? I know title() function but it create problem if string contain number as "1gjmk"
34 odpowiedzi
+ 4
Alright I give up trying to explain what I mean 😂. Here is the code:
S = "1utdhx 3g f g"
new_S = ""
for word in S.split():
if word[0].isdigit():
new_S += word
else:
new_S += word.title()
You change .title() to .upper() if you want the whole word to be capitalized. (Haven't tested it, tell me if it doesn't work)
+ 2
Where is your ttempt ? What have you tried to solve this problem ?
+ 2
AARTI SHELAR I know what you want, and that is not what I was asking about.
I want to see what you have tried, so I can fix it.
In case you haven't yet, try to split the sentence with .split()
Then, loop throught letters of each word, and capitalize them, if they are not numbers.
+ 2
Oops sorry, all you have to do is add a space character at the end of the for loop..
new_S += " "
This is exactly what I mean. If you couldn't figure out how to add a space in my code, then you need to do more problems, without the use of built-in methods.
+ 2
AARTI SHELAR post the link here, so everyone can benefit from your post (if it isn't a duplicate already)
+ 2
AARTI SHELAR my code works, except for one case.
You should check how many spaces there are, because my code adds one space only after each word.
Try to think of how to overcome spaces. You should be able to do it with your current python knowledge.
You can share you attempt here if you still fail, but I want to see something that is close. I don't want to just give an answer, because it won't benefit you.
+ 2
1. Loop throught the setence character by character (starting from second character)
2. Each time, you have two things to check;
1) Check that the character right before is a space
2) The character itself is a letter, and not a number or space
3. If these conditions are satisfied, capitalize the letter, else keep it as it is
+ 2
Guys, I just got to this thread and have read that challenge link. But I'm not getting why spaces is a problem, so what about this space problem?
+ 2
Ipang maybe you did it differently then :). At first, I split up the input and then joined it again using spaces.
The problem is that in some cases there was more than just one space separating words, so my output was missing some spaces.
It is an easy thing to resolve, so I wanted him to try it out first, considering I already showed him how to.
+ 2
noor ul hudah upper capitalizes all the letters, not just the first one
+ 1
Your attempt?
+ 1
AARTI SHELAR okay
+ 1
AARTI SHELAR alright, good luck!
+ 1
AARTI SHELAR
That didn't help clarify unfortunately, maintain?
+ 1
So, finally problem solve regex rock🤗
0
What?
0
S="1utdhx 3g f g"
print(S.title())
# 1Utdhx 3G F G
# I want 1utdhx 3g F G
0
I already try capitalize() function but
It doesn't maintain space after split(),while we use join it doesn't return space separate string I mean it doesn't maintain original string
0
U are not getting my problem
I want to maintain space as original string ?? How you determine how much space user give in string??