removing selected items from a list

Still pretty new so I just took a shot at this for practice. Probably not the best way to do it, but it is A way to do it.

def clean_list(your_list): # takes list as argument
    a_list = your_list
    list_length = len(your_list) 

    # these control the flow of the for loop
    dash_1_found = False 
    first_group_found = False  
    star_2_found = False

    word_counter = 0  # counts the letters in item
    delete_start = 0  # index to start deleting
    delete_end = 0  # index to delete last
    scan_count = 0  # keeps track of words deleted

    for word in a_list:  # for each string in the list
        # create a new list
        word_as_list = [letter for letter in word]

        # for each character in that list
        for letters in word_as_list:
            # if first comment group not found
            if first_group_found is False:
                if letters is "/":  # if character is dash
                    dash_1_found = True  # flag it found
                elif letters is "*":  # if star
                    first_group_found = True  # flag it found
                    # mark the index for later use
                    delete_start = word_counter
            # else if first group found already
            elif first_group_found is True:
                # do the same thing in reverse
                if letters is "*":
                    star_2_found = True
                elif letters is "/":
                    # and mark the index for later use
                    delete_end = word_counter

        word_counter += 1  # increase the counter

    new_list = []  # create a new list
    # for each word in the old list, add it to the
    # new list if the indexes match up
    for word in range(0, list_length): 
        if scan_count < delete_start:
            new_list.append(a_list[word])

        scan_count += 1  # increase the scan count

    return new_list  # return it

So..

your_list = clean_list(your_list) would do the trick. Then just do len(your_list) to get the length.

/r/learnpython Thread