사례 # 1 : 1 차원 튜플
TUPLE_ROLES = (
(912,"Role 21"),
(913,"Role 22"),
(925,"Role 23"),
(918,"Role 24"),
)
TUPLE_ROLES[912] #==> Error because it is out of bounce.
TUPLE_ROLES[ 2] #==> will show Role 23.
DICT1_ROLE = {k:v for k, v in TUPLE_ROLES }
DICT1_ROLE[925] # will display "Role 23"
사례 # 2 : 2 차원 튜플
예 : DICT_ROLES [961] #에 '백엔드 프로그래머'가 표시됩니다.
NAMEDTUPLE_ROLES = (
('Company', (
( 111, 'Owner/CEO/President'),
( 113, 'Manager'),
( 115, 'Receptionist'),
( 117, 'Marketer'),
( 119, 'Sales Person'),
( 121, 'Accountant'),
( 123, 'Director'),
( 125, 'Vice President'),
( 127, 'HR Specialist'),
( 141, 'System Operator'),
)),
('Restaurant', (
( 211, 'Chef'),
( 212, 'Waiter/Waitress'),
)),
('Oil Collector', (
( 211, 'Truck Driver'),
( 213, 'Tank Installer'),
( 217, 'Welder'),
( 218, 'In-house Handler'),
( 219, 'Dispatcher'),
)),
('Information Technology', (
( 912, 'Server Administrator'),
( 914, 'Graphic Designer'),
( 916, 'Project Manager'),
( 918, 'Consultant'),
( 921, 'Business Logic Analyzer'),
( 923, 'Data Model Designer'),
( 951, 'Programmer'),
( 953, 'WEB Front-End Programmer'),
( 955, 'Android Programmer'),
( 957, 'iOS Programmer'),
( 961, 'Back-End Programmer'),
( 962, 'Fullstack Programmer'),
( 971, 'System Architect'),
)),
)
#Thus, we need dictionary/set
T4 = {}
def main():
for k, v in NAMEDTUPLE_ROLES:
for k1, v1 in v:
T4.update ( {k1:v1} )
print (T4[961]) # will display 'Back-End Programmer'
# print (T4) # will display all list of dictionary
main()
dir
명령을 보면,_asdict
기능을 직접 보여줄 개체의 필드가 표시 됩니다.