Whether each element in the list is a child of other elements in the list

know a list, ask whether each element in this list is a child of another element, and if so, delete this element.

list = ["GH", "ACDB", "AB", "ABCFE", "ABDCFE", "ACFE", "ABCD", "ABD", "ACBD", "ACD", "FCBA", "FCDBA", "FCA", "FC", "BACF", "BCF", "BDCF", "BACFE", "BCFE", "BDCFE", "BACD", "BCD", "BD", "CBA", "CDBA", "CA", "CAB", "CDB", "CB", "EF", "EFC", "EFCABD", "EFCBD", "EFCD", "DBACF", "DBCF", "DCF", "DBAC", "DBC", "DC"]

as in the above code, the last element that should be left in list is

list=["ABDCFE","GH"]
Jul.19,2022


<br>

lst = ['GH', 'ACDB', 'AB', 'ABCFE', 'ABDCFE', 'ACFE', 'ABCD', 'ABD', 'ACBD', 'ACD', 'FCBA', 'FCDBA', 'FCA', 'FC', 'BACF', 'BCF', 'BDCF', 'BACFE', 'BCFE', 'BDCFE', 'BACD', 'BCD', 'BD', 'CBA', 'CDBA', 'CA', 'CAB', 'CDB', 'CB', 'EF', 'EFC', 'EFCABD', 'EFCBD', 'EFCD', 'DBACF', 'DBCF', 'DCF', 'DBAC', 'DBC', 'DC']

-sharp
lst1 = []
for i, x in enumerate(lst):
    index = i
    for y in lst:
        if x != y and len(set(x).intersection(set(y))) == len(x):
            index = -1
            break

    if index != -1:
        lst1.append(x)

print lst1

-sharp
lst1 = []
for i, x in enumerate(lst):
    index = i
    for y in lst:
        if x != y and x in y:
            index = -1
            break

    if index != -1:
        lst1.append(x)

print lst1
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b99b93-2e929.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b99b93-2e929.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?