WGUlD522lObjectivelAssessmentl(Newl
Update)lPythonlforlITlAutomation|lQsl&lAs|
l100%lCorrect|lGradelAl(VerifiedlAnswers)
QUESTION
WhatlislthelprimaryladvantageloflusingldictionarieslinlPython?
Answer:
lDictionar-
lieslallowlyoultolassociatelvalueslwithldescriptivelkeys,lprovidinglalconvenientlwayltolrepresen
tlrelationshipslbetweenldata
QUESTION
WhichlPythonlcodelsnippetlcorrectlyldemonstrateslthelcreationloflaldictionarylwithlkey-
valuelpairs?
Answer:
ldevicesl=l{'Router1':l'192.168.1.2',l'Switch2':
'10.0.0.2'}
l
QUESTION
WhichlPythonlcodelsnippetlcorrectlyldemonstrateslthelcreationloflaldictionarylwithlvariousldata
ltypeslforlbothlkeyslandlvalues?
Answer:
ldata_typesl=
{'string_key':l[1,l2,l3],l(4,l5,l6):l'tuple_key'}
QUESTION
WhichlPythonlcodelsnippetlcorrectlyldemonstratesltheluselofltheldictio-
lnarylconstructor,ldict()?
,\
Answer:
ldl=ldict([('key1',l'value1'),l('key2',l'value2')])
QUESTION
WhichlPythonlcodelsnippetlcorrectlyldemonstrateslhowltolaccesslanlitemlinlaldictionarylusingli
tslkey?
Answer:
ldict2l=l{"keyA":l"valueA",l"keyB":l"valueB"};lvaluel=ldict2["keyA"]
QUESTION
WhichlPythonlcodelsnippetlcorrectlyldemonstrateslhowltolchangelthelvalueloflalspecificlkeylinl
aldictionary?
Answer:
ldevicesl=l{"DeviceA":l"192.168.1.1",l"DeviceB":l"10.0.0.1"};ldevices["DeviceA"]l=l"192.168.
1.100"
QUESTION
WhichlPythonlcodelsnippetlcorrectlyldemonstratesltheluseloflthelupdate()lmethodltolupdatelaldi
ctionarylwithlthelkey/valuelpairslfromlanotherldictio-lnary?
Answer:
linfo1l=l{"A":l"1",l"B":l"2"};linfo2l=l{"B":l"3",l"C":l"4"};linfo1.update(info2)
QUESTION
HowlcanlanlitemlbeladdedltolalPythonldictionary?
Answer:
lByldirectlylassigninglalvalueltolalnewlkeylinltheldictionary
,\
QUESTION
WhichlPythonlcodelsnippetlcorrectlyldemonstrateslhowltolremovelanlitemlfromlaldictionary?
Answer:
ldict3l=l{"keyX":l"valueX",l"keyY":l"valueY"};ldelldict3["keyX"]
QUESTION
Whatldoeslthelclear()lmethodldolinlalPythonldictionary?
Answer:
lItlremoveslalllitemslfromltheldictionary
QUESTION
WhichlPythonlcodelsnippetlcorrectlyldemonstratesltheluseloflalsetltolmaintainlalcollectionloflun
iquelitems?
Answer:
ldevicesl=l{'Switch',l'Router',l'Firewall'};lnew_devicesl=l{'Firewall',l'LoadlBalancer'};ldevicesl=
ldevices.union(new_devices)
QUESTION
HowlcanlalsetlbelcreatedlinlPython?
Answer:
lBylplacinglalcomma-separatedlse-
lquenceloflitemslinsidelcurlylbracesl{}lorlusinglthelset()lfunction
QUESTION
WhatlislthelprimarylcharacteristicloflalsetlcreatedlusinglthelPythonlsetlconstructor,lset()?
Answer:
lAlsetlcreatedlusinglset()lholdslanlunorderedlcollectionlofluniquelitems
, \
QUESTION
HowlcanlyoulcheckliflalspecificlitemlislpresentlinlalPythonlset?
Answer:
lBylusinglthelinlkeyword
QUESTION
HowlcanlitemslbeladdedltolalPythonlset?
Answer:
lBylusingltheladd()lmethodlforlalsinglelitemlandlthelupdate()lmethodlforlmultiplelitems
QUESTION
Whatldoeslthelupdate()lmethodldolinlalPythonlset?
Answer:
lItladdslitemslfromlanotherlsetlintolthelcurrentlset
QUESTION
Whatlisltheldifferencelbetweenlthelremove()landldiscard()lmethodslinlalPythonlset?
Answer:
lThelremove()lmethodlraiseslanlerrorliflthelitemldoeslnotlexistlinlthelset,lwhileltheldiscard()lme
thodldoeslnot
QUESTION
Whatldoeslthelclear()lmethodldolinlPython?
Answer:
lItlemptieslalset,lremovinglalllitems
l