Skip to content

Instantly share code, notes, and snippets.

@searge
Last active October 9, 2018 15:44
Show Gist options
  • Save searge/11f85a0452ad650376e00760c245d0d5 to your computer and use it in GitHub Desktop.
Save searge/11f85a0452ad650376e00760c245d0d5 to your computer and use it in GitHub Desktop.

Revisions

  1. searge revised this gist Oct 9, 2018. 1 changed file with 18 additions and 0 deletions.
    18 changes: 18 additions & 0 deletions most_frequent_in_list.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    '''
    MOST FREQUENT
    element in a list
    '''

    a = [1 2, 3, 1, 2, 3, 2, 2, 4, 5, 1]

    print(max(set(a), key = a.count))

    '''
    using Counter
    from collections
    '''

    from collections import Counter

    cnt = Counter(a)
    print(cnt.most_common(3))
  2. searge revised this gist Oct 9, 2018. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions one_string_from_list.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    '''
    Об'єднати список в стрічку
    '''

    a = ['Python', 'is', 'awesome']
    print(' '.join(a))
  3. searge created this gist Oct 9, 2018.
    10 changes: 10 additions & 0 deletions exchange.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    '''
    Pythonic way of
    VALUE SNAPPING
    '''

    a, b = 5, 10
    print(a, b)

    a, b = b, a
    print(a, b)