Click here to Skip to main content
15,898,010 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I get different lists from a random list generator and I have to check which of these lists would be accepted, the condition : the elements of the same type are grouped together ,other elements are not concerned. For example : L1 = [Device1,Device2,Device3,Device4,Device5,Device6,Device7,Device8] every device has a type: TypeL1 =[H,U,U,K,D,P,F,D] a correct config would be: [x,U,U,x,D,D,x,x].

What I have tried:

in my code I tried to find the repeated elements indexes and then I sorted them and saved in an another list. But it doesn't help me too much. for the above example I got L=[U,U,D,D].I'm stuck and I'm in luck of ideas.Im a beginner in Programming so any help will be great.
Python
D=[i for i ,x in enumerate (check_type)if check_type.count(x)> 1]
    logging.info("the index repeted elem : %s",D)
    X = len(D)
    print ("length D:",X)
    Flag.clear()
    while len(D)>1:
        A=check_type[int(D[0])]
        print("A:",A)
        for i in range(0,len(D)):
            if check_type[int(D[i])] == A:
                Flag.append(D[i])
        print ("Flag:",Flag )

        D=list(set(D).difference(Flag))
        print ("D:",D)
    logging.info("the sorted indexes:%s",Flag)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900