Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,923 questions

51,856 answers

573 users

How to check if a string can split into 4 distinct substrings in Python

1 Answer

0 votes
def canSplitInto4DistinctSubstrings(s):
    size = len(s)
    
    if size < 4:
        return False

    for i in range(1, size):
        for j in range(i + 1, size):
            for k in range(j + 1, size):
                s1 = s[:i]
                s2 = s[i:j]
                s3 = s[j:k]
                s4 = s[k:]
                if (len(s1) > 0 and len(s2) > 0 and len(s3) > 0 and len(s4) > 0): 
                    if (s1 != s2 and s1 != s3 and s1 != s4 and s2 != s3 and s2 != s4 and s3 != s4):
                        print(s1, s2, s3, s4)
                        return True

    return False

s = "AlbusDumbledore"
if canSplitInto4DistinctSubstrings(s):
    print("Yes")
else:
    print("No")
    
    
    
''' 
run:

A l b usDumbledore
Yes

'''

 



answered Feb 15, 2024 by avibootz

Related questions

...