Python 3.4 - Sets

 You can use a set to make sure any redundancy is eliminated from a list.A set cannot have two of the same item.

groceries = {'milk', 'bacon', 'coffee', 'milk', 'eggs', 'diapers'}

print(groceries)

if 'milk' in groceries:
    print('you already have it')

else:
    print('you need some')

/Users/mattfassnacht/PycharmProjects/untitled10/venv/bin/python /Users/mattfassnacht/PycharmProjects/untitled10/string.py
{'eggs', 'bacon', 'milk', 'diapers', 'coffee'}
you already have it

Process finished with exit code 0


https://www.youtube.com/watch?v=23eY8n08pMc

Comments

Popular posts from this blog

Pyhton 3.4 - Continue

Conversations Ongoing: Valuing Modernization in Early European History

Conversations Ongoing: A Bunch of Amateurs