• + 0 comments
    def happyLadybugs(b):
        #first check: no space in this string , True if they are already friends , false else
        if b.count("_")<1:
            liste=[]
            for i in b:
                if i not in liste:
                    liste.append(i)
            res_list= list(map(lambda x :b.count(x)*x,liste))
            if "".join(res_list)==b:
                for i in b:
                    if b.count(i)==1:
                        return "NO"
                return "YES"
            else:
                return "NO"
        #second check : if all the string is underscore     
        elif b.replace("_","")=="":
            return "YES"
        #third check : if you survived the first two , one space(underscore) should be enough to validate the happy bugs
        else:
            bug_set = set(b.replace("_",""))
            bug_string="".join(bug_set)
            for i in bug_string:
                if b.count(i)==1:
                    return "NO"
            return "YES"