Python - How to change values in a list of lists?

后端 未结 8 2017
鱼传尺愫
鱼传尺愫 2021-02-07 20:14

I have a list of lists, each list within the list contains 5 items, how do I change the values of the items in the list? I have tried the following:

    for [ite         


        
8条回答
  •  名媛妹妹
    2021-02-07 20:49

    Here is an example I used recently, it was a real mind bender but hopefully it can help out some one!

    pivot_peaks is a list of pandas data frames some of them are duplicates.

    # Create a new list with only a single entry for each item
    new_list = []
    
    for obj_index, obj in enumerate(pivot_peaks):
        add_new_frame = False
    
        if len(new_list) == 0:
            new_list.append(obj)
        else:
            for item in new_list:
                if item.equals(obj):
                    add_new_frame = False
                    break
                else:
                    add_new_frame = True
    
            if add_new_frame == True:
                new_list.append(obj)
    

提交回复
热议问题