Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save DugalMcCrow/cff86648e8c36c47ebbe9054d4acf3e6 to your computer and use it in GitHub Desktop.

Select an option

Save DugalMcCrow/cff86648e8c36c47ebbe9054d4acf3e6 to your computer and use it in GitHub Desktop.

Revisions

  1. @ycui1 ycui1 created this gist May 22, 2020.
    10 changes: 10 additions & 0 deletions medium_concise_code_dc.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    >>> # Dictionary comprehension
    >>> squares_dict = {number: number*number for number in numbers}
    >>> squares_dict
    {1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36}
    >>>
    >>> # Set comprehension
    >>> numbers_dups = [1, 2, 3, 4, 3, 2, 1]
    >>> squares_set = {number*number for number in numbers_dups}
    >>> squares_set
    {16, 1, 4, 9}