Skip to content

Instantly share code, notes, and snippets.

@monzee
Forked from isa/gist:2571012
Created May 1, 2012 23:11
Show Gist options
  • Select an option

  • Save monzee/2572256 to your computer and use it in GitHub Desktop.

Select an option

Save monzee/2572256 to your computer and use it in GitHub Desktop.

Revisions

  1. monzee revised this gist May 1, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    ['E', 'D', 'J'],
    ]
    pairs = map(sorted, chain(*[combinations(row, 2) for row in data]))
    pairfreq = sorted(set(sorted(tuple(pair) + (pairs.count(pair),) for pair in pairs)))
    pairfreq = sorted(set(tuple(pair) + (pairs.count(pair),) for pair in pairs))
    map(print, pairfreq)

    """
  2. monzee revised this gist May 1, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,8 @@
    ['E', 'D', 'J'],
    ]
    pairs = map(sorted, chain(*[combinations(row, 2) for row in data]))
    map(print, sorted(set(sorted(tuple(pair) + (pairs.count(pair),) for pair in pairs))))
    pairfreq = sorted(set(sorted(tuple(pair) + (pairs.count(pair),) for pair in pairs)))
    map(print, pairfreq)

    """
    Question: Convert following into the latter data structure in less than 30 lines:
  3. monzee revised this gist May 1, 2012. 2 changed files with 36 additions and 22 deletions.
    36 changes: 36 additions & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    from __future__ import print_function
    from itertools import chain, combinations
    data = [
    ['A', 'B', 'C'],
    ['A', 'C', 'E'],
    ['E', 'F', 'D'],
    ['D', 'A', 'J'],
    ['E', 'D', 'J'],
    ]
    pairs = map(sorted, chain(*[combinations(row, 2) for row in data]))
    map(print, sorted(set(sorted(tuple(pair) + (pairs.count(pair),) for pair in pairs))))

    """
    Question: Convert following into the latter data structure in less than 30 lines:
    List:
    A, B, C
    A, C, E
    E, F, D
    D, A, J
    E, D, J
    List
    A, B, 1 (frequency)
    A, C, 2
    A, D, 1
    A, E, 1
    A, J, 1
    B, C, 1
    C, E, 1
    D, E, 2
    D, F, 1
    D, J, 2
    E, F, 1
    E, J, 1
    """
    22 changes: 0 additions & 22 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,22 +0,0 @@
    Question: Convert following into the latter data structure in less than 30 lines:

    List:
    A, B, C
    A, C, E
    E, F, D
    D, A, J
    E, D, J

    List
    A, B, 1 (frequency)
    A, C, 2
    A, D, 1
    A, E, 1
    A, J, 1
    B, C, 1
    C, E, 1
    D, E, 2
    D, F, 1
    D, J, 2
    E, F, 1
    E, J, 1
  4. Isa Goksu created this gist May 1, 2012.
    22 changes: 22 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    Question: Convert following into the latter data structure in less than 30 lines:

    List:
    A, B, C
    A, C, E
    E, F, D
    D, A, J
    E, D, J

    List
    A, B, 1 (frequency)
    A, C, 2
    A, D, 1
    A, E, 1
    A, J, 1
    B, C, 1
    C, E, 1
    D, E, 2
    D, F, 1
    D, J, 2
    E, F, 1
    E, J, 1