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.
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)