Monday 15 September 2014

how to compare two list ,object instances in python -


Say I have:

  list1 = [1,6] list 2 = [1]   

I want to do something if the list value matches!

Comparing it and then stuff

  if list1 == list2: # Compare lists for similarity doStuff (if not) # If there is a similarity of lists, then = "post-text" itemprop = "text"> 

then do stuff

Of course , You need to clarify that "if the values ​​of the lists match", then what does it mean? It will be checked to check that the two lists have the same status in the same position - that is, if they are equal .

Edit:

The question is not clear, let's look at some possible explanations. To see if all the elements of list1 are also in list2 :

  if all (x for list x 2 in list2) ): To do something with each element in DoStuff ()   

or list1 , also in list2 , do this :

  (list1) & amp; Set (list2): doStuff (e)    

No comments:

Post a Comment