#NEWLINE# def collections_to_string( iterable , threshold = ( - 1 ) ) : #NEWLINE# #INDENT# "\n\n    >>> collections_to_string([])\n    ''\n    >>> collections_to_string([1])\n    '1'\n    >>> collections_to_string([1, 2])\n    '1 and 2'\n    >>> collections_to_string([1, 2, 3, 4])\n    '1, 2, 3, and 4'\n    >>> collections_to_string([1, 2, 3, 4], threshold=4)\n    '1, 2, 3, and 4'\n    >>> collections_to_string([1, 2, 3, 4, 5, 6], threshold=4)\n    '1, 2, 3, 4, and 2 items'\n    >>> collections_to_string([1, 2, 3, 4, 5], threshold=4)\n    '1, 2, 3, 4, and 5'\n    >>> collections_to_string([1, 2, 3, 4], threshold=20)\n    '1, 2, 3, and 4'\n\n    " #NEWLINE# if ( len ( iterable ) == 0 ) : #NEWLINE# #INDENT# return '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( iterable ) < 2 ) : #NEWLINE# #INDENT# return str ( iterable [ 0 ] ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( threshold == ( - 1 ) ) or ( threshold >= len ( iterable ) ) ) : #NEWLINE# #INDENT# threshold = ( len ( iterable ) - 1 ) #NEWLINE# #UNINDENT# comman_list = [ ] #NEWLINE# and_item = None #NEWLINE# for ( idx , item ) in enumerate ( iterable ) : #NEWLINE# #INDENT# if ( and_item is not None ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( comman_list ) < threshold ) : #NEWLINE# #INDENT# comman_list . append ( item ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( idx == ( len ( iterable ) - 1 ) ) : #NEWLINE# #INDENT# and_item = item #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# remainder_length = ( len ( iterable ) - idx ) #NEWLINE# and_item = '{} items' . format ( remainder_length ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return ( ( ( ', ' . join ( map ( str , comman_list ) ) + ( ',' if ( len ( comman_list ) > 2 ) else '' ) ) + ' and ' ) + str ( and_item ) )