Skip to content

Instantly share code, notes, and snippets.

@2tony2
Created May 22, 2024 07:27
Show Gist options
  • Select an option

  • Save 2tony2/d11c768b9161b9fcb75a48f9d6540319 to your computer and use it in GitHub Desktop.

Select an option

Save 2tony2/d11c768b9161b9fcb75a48f9d6540319 to your computer and use it in GitHub Desktop.
from typing import TypeVar, List
T = TypeVar('T')
def duplicate(item: T) -> List[T]:
return [item, item]
# Usage examples
print(duplicate(123)) # [123, 123]
print(duplicate("Hello")) # ['Hello', 'Hello']
print(duplicate([1, 2, 3])) # [[1, 2, 3], [1, 2, 3]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment