mercredi 30 août 2017

Appending elements to a list based on condition

I was trying to append few elements to a list list_accepted_outsidenestant. I have shown part of code relevant to the current section. When i try to print the list list_accepted_outsidenestant, i get: list_accepted_outsidenestant- [([971, 977, 728, 740], set([728, 977, 971, 740]))]. The list is showing the same elements in set too. Can anyone pointout the mistake i am doing? Because of this, i am getting an error: set_accepted_outsidenest_antlist = set(list_accepted_outsidenestant TypeError: unhashable type: 'list'

def leo(tag_data):
    available_ants_outside = []
    ori = []
    for id, (x, y) in tag_data:
        available_ants_outside.append(id)
        if for_coordinates_outside_nest((x, y)) is True:
            ori.append(id)
    return ori


def virgo(tag_data):
    available_ants_inside = []
    list_insidenest_ant_id = []
    set_inside_nest_ant_id = set()
    for id, (x, y) in tag_data:
        available_ants_inside.append(id)
        if for_coordinates_inside_nest((x, y)) is True:
            list_insidenest_ant_id.append(id)
            set_inside_nest_ant_id = set(list_insidenest_ant_id)
            return list_insidenest_ant_id,set_inside_nest_ant_id

 def bambino(ori,list_insidenest_ant_id):
    list_accepted_outsidenestant = []                       
    set_accepted_outsidenest_antlist = set()
    set_accepted_insidenest_antlist = set()
    if len(list_accepted_outsidenestant) < num_accepted:
        if (len(ori) > 0) or (len(list_insidenest_ant_id) >0):
            list_accepted_outsidenestant.append(ori[0:min(len(ori),             
            num_accepted-len(list_accepted_outsidenestant))])
            set_accepted_outsidenest_antlist = set(list_accepted_outsidenestant)  
            print "list_accepted_outsidenestant-" + str(list_accepted_outsidenestant)
            set_accepted_insidenest_antlist  = set(list_insidenest_ant_id)
    return set_accepted_outsidenest_antlist,set_list_outsideant_id,set_accepted_insidenest_antlist

Aucun commentaire:

Enregistrer un commentaire