Skip to Content
Secret Recipes of the Python Ninja
book

Secret Recipes of the Python Ninja

by Cody Jackson
May 2018
Intermediate to advanced content levelIntermediate to advanced
380 pages
9h 37m
English
Packt Publishing
Content preview from Secret Recipes of the Python Ninja

setlist

  1. ext_collections_setlist.py demonstrates how to use setlist:
      >>> from collections_extended import setlist      >>> import string      >>> sl = setlist(string.ascii_lowercase)      >>> sl      setlist(('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'))      >>> sl[3]      'd'      >>> sl[-1]      'z'      True      >>> sl.index('m')  # so is finding the index of an element      12      >>> sl.insert(1, 'd')  # inserting an element already in raises a ValueError      Traceback (most recent call last):      ...         raise ValueError      ValueError      >>> sl.index('d')      3
    • First, setlist has to be imported. We also import the string class to provide access to its public module variables.
    • A setlist instance is created, using the string ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Expanding World of Python

The Expanding World of Python

Dane Hillard

Publisher Resources

ISBN: 9781788294874Supplemental Content