Skip to content

Commit dc670a3

Browse files
author
Vitalii Cherkashyn
authored
list unpacking
1 parent f143d10 commit dc670a3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

list/list_unpacking.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import List
2+
from typing import Union
3+
4+
# multi type declaration
5+
def get_names(prefix: str, names: Union[str, List]) -> Union[str, List]:
6+
if isinstance(names, List):
7+
return [prefix+each_name for each_name in names]
8+
else:
9+
return prefix+names
10+
11+
# unpacking
12+
a,b = get_names("___", ["one", "two"])
13+
c = get_names("___", "figure")
14+
15+
print(a,b,c)

0 commit comments

Comments
 (0)