Comparison of two numbers in the algorithm

1. In fact, when comparing trees, the idea must be clear. The recursive operation on the tree must be both empty, or one is empty and the other is not empty, or both are not empty but the value is not equal , So recursion can be used, and iterative operations are performed only if the two are not empty and the values ​​are equal.
2.

  • When .reverse()looking for the reverse operation of a list, if you use it directly , you must remember that reverse does not take d! ! ! ! Not reversed
  • Or if you want to use reversed operations on the list, then it must be a = list(reversed(a)), it must be listed ! ! ! , Remember! !
  • Of course, you can also slice, a = a [::-1]

3. Suddenly found that the a.reverse () operation will not return any value! ! , It's too cowhide, print (a.reverse ()) received is None, understand that this is just an operation on a, return None

4. It is all() 函数used to judge whether all elements in the given iterable parameter iterable are TRUE, if it returns True, otherwise it returns False.
The elements are true except for 0, empty, None, False.

5. append& extendDifference
list.append(object)Add an object to the list and add
list.extend(sequence)the contents of a sequence seq to the list.
Here is the code:

music_media = ['compact disc', '8-track tape', 'long playing record']
new_media = ['DVD Audio disc', 'Super Audio CD']
music_media.append(new_media)
print music_media
---- output ----
>>>['compact disc', '8-track tape', 'long playing record', ['DVD Audio disc', 'Super Audio CD']]

When using append, the new_media is regarded as an object, and the whole package is added to the music_media object.

music_media = ['compact disc', '8-track tape', 'long playing record']
new_media = ['DVD Audio disc', 'Super Audio CD']
music_media.extend(new_media)
print music_media
---- output ----
>>>['compact disc', '8-track tape', 'long playing record', 'DVD Audio disc', 'Super Audio CD']
Published 31 original articles · praised 0 · visits 672

Guess you like

Origin blog.csdn.net/ballzy/article/details/105686595