You have been given the following lists of Color and their specific codes:
Colors = ['Red','Blue','Green','Black','Yellow',‘Orange’,‘Purple’,‘Nocolor’]
Codes = [97,17,19,128,66,111,231,00]
1. Using codeDict, find the score for 'Nocolor'.
2. Add a code of 333 for 'Nocolor'.
3. Create a sorted list of all the codes in codeDict.
4. Update the name for 'Nocolor' to be ‘white’
5. White was not a part of original colors list so, just Delete it and its code from codeDict.
USE PYTHON CONSOLE AND SUBMIT THE PYTHON SCRIPTS FOR ALL FIVE QUESTIONS
Colors = ['Red','Blue','Green','Black','Yellow','Orange','Purple','Nocolor']
Codes = [97,17,19,128,66,111,231 ,0]
codeDict = {Colors[i]:Codes[i] for i in range(len(Colors))}
# answer 1.
print("code for Nocolor is",codeDict['Nocolor'])
#answer 2.
codeDict['Nocolor'] = 333
# answer 3
Sorted_Codes = []
for color in Colors:
Sorted_Codes.append(codeDict[color])
Sorted_Codes.sort()
print("sorted code list",Sorted_Codes)
# answer 4.
codeDict['white'] = codeDict['Nocolor']
del codeDict['Nocolor']
# answer 5.
del codeDict['white']
Get Answers For Free
Most questions answered within 1 hours.