Home > Mobile >  How to avoid Overriding in Python after extracting values from a dictionary
How to avoid Overriding in Python after extracting values from a dictionary

Time:05-27

Here is a dictionary containing the following content: Description_list ={'ClickUrl': 'http*', 'AngryUser': 'Hate', 'HelloGoodBye': 'Hello', 'Social': "I'd like to learn more about the team"}

I am trying to set the values of the above dictionary one by one via the join but it is somehow overriding the previous ones

temp2 = 1    
        if temp2==1:
            temp2 = temp2 1
            for key in Description_list.keys():
                        print (Description_list)
                        if key not in sample_node:
                                val1 = Description_list[key]
                                
                                if val1 not in i_x_0:
                                    
                                        i_x_0.text = ''.join(val1)      

Sample_node is the node in the element Tree and i_x_0 is the sub element of the node in which I am trying to set the text from the dictionary, but somehow string is being overridden, any suggestions to make it right?

CodePudding user response:

You can try via appending this :

i_x_0.text.append(val1)

It might work for this loop

CodePudding user response:

Below snippet somewhat does the work

if temp_1==1:
            temp_1 = temp_1 1
            for key1,val1 in Description_list.items():
                #val1 = Description_list[key1]
                print("print key",val1)
                if val1 not in i_x_0:
                    
                    
                        i_x_0.text = val1      
                        print("print val1",i_x_0.text)
``` but it might need more refactoring 
  • Related