Lists of list

Discussion in 'Python' started by Mohammed Altaj, Aug 17, 2005.

  1. Hi All

    I am having problem with delete line if its belong to another one , example

    ['0132442\n', '13\n', '24\n']

    the 2nd and 3rd are already in the first line , how can do this !!!

    Thanks
    Mohammed Altaj, Aug 17, 2005
    #1
    1. Advertising

  2. Mohammed Altaj

    BranoZ Guest

    Mohammed Altaj wrote:
    > Hi All
    >
    > I am having problem with delete line if its belong to another one , example


    I think, you mean to remove all lines that are substrings of another
    line.

    l = ['0132442\n', '13\n', '24\n']
    l = [e.strip() for e in l]

    i = 0
    while True:
    try:
    for j in range(len(l)):
    if i == j:
    continue
    if l[j].find(l) >= 0:
    # line 'j' is superstring of line 'i'
    del l
    break
    else: # doesn't have superstring
    i += 1
    except IndexError:
    break

    Basically, I try all n*n combinations, and remove substring lines
    "in-place".

    BranoZ
    BranoZ, Aug 17, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JustSomeGuy

    Sorting lists of lists...

    JustSomeGuy, Jun 17, 2004, in forum: C++
    Replies:
    0
    Views:
    300
    JustSomeGuy
    Jun 17, 2004
  2. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    377
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
  3. yomgui

    list of lists of lists ....

    yomgui, Jul 28, 2006, in forum: Python
    Replies:
    6
    Views:
    294
    yomgui
    Jul 31, 2006
  4. bahoo
    Replies:
    3
    Views:
    287
    Bruno Desthuilliers
    Apr 3, 2007
  5. antar2
    Replies:
    2
    Views:
    373
    Bighead
    Jul 17, 2008
Loading...

Share This Page