Single-Item Tuple Creation¶
The one
function provides a cleaner alternative to Python’s comma-syntax
for creating single-item tuples. It can be used directly from the package or
installed into builtins.
Basic Usage¶
Import and use directly from the package:
>>> from frigid import one
>>> single42 = one( 42 )
>>> single42
(42,)
This is equivalent to the standard comma-syntax but more readable in many contexts:
>>> one( 42 ) == ( 42, )
True
Common Use Cases¶
Creating lists of single-item tuples is clearer with one
:
>>> numbers = [ one( x ) for x in range( 3 ) ]
>>> numbers
[(0,), (1,), (2,)]
It works well with map
and other higher-order functions:
>>> tuple( map( one, [ 'a', 'b', 'c' ] ) )
(('a',), ('b',), ('c',))
Installation¶
The function can be installed into builtins for easier access:
>>> from frigid import install
>>> install( ) # Installs as 'one'
>>> one( 'test' ) # Now available globally
('test',)
>>> install( 'single' ) # Install with custom name
>>> single( 'test' )
('test',)