1, List A, b,a=a+b efficiency is lower than a.extend (b), because the former is generated after the a+b of a new list and then assigned to a, and the latter is based on the original A to expand the B
2. The Join method of the string module is the inverse method of the split method. Eg:seq = [' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 '];sep = ', '; s = sep.join (seq)
3. The title method of the string converts the string to a title, which is the first letter of all words, and the other letters are lowercase. String = "That's all folks."; String.title () = = "That's all folks."
4, Exchange two values x,y = Y,x
5,
Use Iteritems rather than items
Iteriterms is using generators, so when iterating a large sequence is this method better
D={1: "1", 2: "2", 3: "3"}
For key, Val in D.items () # calls items () to build a complete list object
For Keys, Val in D.iteritems () # Only one value is generated per request at iteration time
This scenario and range have a similar relationship to xrange.