Home > OS >  Printing only non-full-capital "words" from a string?
Printing only non-full-capital "words" from a string?

Time:02-16

I got a small problem that im not sure how I should start to crack

Lets say I have a string that goes:

heLlo HUMANS, toDay IS A DAMN good DAY is IT not?

And I needed to make the string like this without imports like regex:

heLlo, toDay good is not?

How should I go about it?

CodePudding user response:

Try it:-

string = "heLlo HUMANS, toDay IS A DAMN good DAY is IT not?"

for words in string:
    if words.islower()
         print(words)

CodePudding user response:

To create a string with the words that are not uppercase you could do:

def string_without_upper(s):
    only_mixed_or_lower_case = list()
    for word in s.split(' '):
        if not word.isupper():
            only_mixed_or_lower_case.append(word)
    return ' '.join(only_mixed_case)

s = "heLlo HUMANS, toDay IS A DAMN good DAY is IT not?"
print(string_without_upper(s))

This will however not keep the punctuation like in your example. Is that something you need?

CodePudding user response:

string = "heLlo HUMANS, toDay IS A DAMN good DAY is IT not?".split()

for word in string:
    if not word.isupper():
        print(word)
  • Related