GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — python-notes/python-iterables.md at main · smenjas/python-notes

Expand file tree

/

python-iterables.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
56 lines (52 loc) · 1.85 KB
/

python-iterables.md

Copy path

File metadata and controls

56 lines (52 loc) · 1.85 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

Python Iterables

This covers Python's built in iterable data types:

  • Lists
  • Tuples
  • Dictionaries
  • Sets Also see Python's standard library collections.

Lists

  • Lists are ordered collections of values, indexed starting at zero.
  • Lists are mutable. You can change their contents and their order.
  • Lists can contain any data type.
  • Lists have a sort method, that reorders them in place.
  • Lists are contiguous memory allocations, stored just like the list.
my_list = list()
my_list = []
my_list.sort()

Tuples

  • Tuples are ordered collections of values, indexed starting at zero.
  • Tuples are immutable. You cannot change their contents or their order.
  • Tuples can contain any other data type.
  • Tuples can contain lists. The list entries can change, but not the address.
  • Tuples don't have a sort method. Use sorted(), to copy into a list.
my_tuple = tuple()
my_tuple = ()
my_tuple = 0,
my_sorted_list = sorted(my_tuple)

Dictionaries

  • Dictionaries are collections of keys mapped to values, indexed by hash.
  • Dictionary order is based on history, and changes when the dictionary grows.
  • Dictionary keys must be immutable: numbers, strings, and some tuples.
  • Dictionary keys are unique, you cannot have duplicates.
  • Dictionary values can be any data type.
  • Dictionaries don't have a sort method. Use sorted(), to copy into a list.
  • Dictionaries are implemented using a hash map/table.
my_dict = dict()
my_dict = {}
my_sorted_dict = sorted(my_dict)

Sets

  • Sets are dictionaries without values.
  • Set keys are unique, you cannot have duplicates.
my_set = set()
my_set = {0} # Empty braces create a dictionary.
my_sorted_set = sorted(my_set)
unique_entries = set(my_list) # Easy way to remove duplicates.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.