Python
  Home arrow Python arrow Page 3 - Python Sets
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

Python Sets
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 8
    2007-12-03


    Table of Contents:
  • Python Sets
  • Adding to a Set
  • Copying Sets and Testing for Membership
  • Removing Data from A Set
  • Don't Make Me Repeat Myself!
  • Using Operators on Sets

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Python Sets - Copying Sets and Testing for Membership
    ( Page 3 of 6 )

    If you want to copy a Set, you can do so pretty simply:


    /usr/local/bin/python


    mcdonaldgang = Set (['Grimace', 'Hamburglar', 'Mayor Mccheese', 'Burger King', 'Wendy', 'Fry Guy'])

    gang = mcdonaldgang.copy()

    print gang

    Here would be the result of this program:

      Fry Guy Grimace Mayor Mccheese Hamburglar Burger King Wendy

    Suppose the gang had grown so large Ronald couldn't keep track of it in his head. To see if someone was in his gang, he could use the In operator.


    /usr/local/bin/python


    mcdonaldgang = Set (['Grimace', 'Hamburglar', 'Mayor Mccheese', 'Burger King', 'Wendy', 'Fry Guy'])


    'Grimace' in mcdonaldgang

    'Birdie' in mcdonaldgang

    This program checks to see if Grimace and Birdie are in the McDonald's Gang. Here is the result:

      True

      False

    Meaning that Grimace is in the gang, but Birdie is not. Who cares...she was annoying anyway. And now you know where those chicken nuggets come from.



     
     
    >>> More Python Articles          >>> More By James Payne
     

       

    PYTHON ARTICLES

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT