Содержание
- 2. Lists An ordered group of items Does not need to be the same type Could put
- 3. Methods of Lists List.append(x) adds an item to the end of the list List.extend(L) Extend the
- 4. Examples of other methods a = [66.25, 333, 333, 1, 1234.5] //Defines List print a.count(333), a.count(66.25),
- 5. Using Lists as Stacks The last element added is the first element retrieved To add an
- 6. Using Lists as Queues First element added is the first element retrieved To do this collections.deque
- 7. List Programming Tools Filter(function, sequence) Returns a sequence consisting of the items from the sequence for
- 8. Map Function Map(function, sequence) Calls function(item) for each of the sequence’s items Computes the cube for
- 9. Reduce Function Reduce(function, sequence) Returns a single value constructed by calling the binary function (function) Computes
- 10. The del statement A specific index or range can be deleted
- 11. Tuples Tuple A number of values separated by commas Immutable Cannot assign values to individual items
- 12. Sets An unordered collection with no duplicate elements Basket = [‘apple’, ‘orange’, ‘apple’, ‘pear’] Fruit =
- 13. Dictionaries Indexed by keys This can be any immutable type (strings, numbers…) Tuples can be used
- 14. Looping Techniques Iteritems(): for retrieving key and values through a dictionary
- 15. Looping Techniques Enumerate(): for the position index and values in a sequence
- 16. Zip(): for looping over two or more sequences
- 18. Скачать презентацию