gadgets = ["Mobile", "Laptop", 100, "Camera", 310.28, "Speakers", 27.00, "Television", 1000, "Laptop Case", "Camera Lens"]
Answers
Answer:
gadgets = [“Mobile”, “Laptop”, 100, “Camera”, 310.28, “Speakers”, 27.00, “Television”, 1000, “Laptop Case”, “Camera Lens”]
a) Creating a separate list of strings and numbers by checking each element of the list.
gadgets = ["Mobile", "Laptop", 100, "Camera", 310.28, "Speakers", 27.00, "Television", 1000, "Laptop Case", "Camera Lens"]
sl = list()
nl = list()
for i in gadgets:
if type(i) == str:
sl.append(i)
else:
nl.append(i)
print(sl, "is the list of string values.")
print(nl, "is the list of numerical values.")
b) Sorting the strings list in ascending order.
This is done with the view that it proceeds from the above coding. If not, a program will have to be made to create a list solely for string, something similar to the one above, excluding the numerical part.
sl.sort()
print(sl)
c) Adding an element 56.89 to the number list.
nl.append(56.89)
print(nl)
d) Replacing the element "Speakers" to "Headphones".
sl.replace("Speakers", "Headphones")
print(sl)
e) Deleting the second element of the numbers list.
del nl[1]
print(nl)
f) Displaying the modified strings and number lists.
print(sl, "is the new list of strings.")
print(nl, "is the new list of numbers.")
gadgets = [“Mobile”, “Laptop”, 100, “Camera”, 310.28, “Speakers”, 27.00, “Television”, 1000, “Laptop Case”, “Camera Lens”]
a) Creating a separate list of strings and numbers by checking each element of the list.
gadgets = ["Mobile", "Laptop", 100, "Camera", 310.28, "Speakers", 27.00, "Television", 1000, "Laptop Case", "Camera Lens"]
sl = list()
nl = list()
for i in gadgets:
if type(i) == str:
sl.append(i)
else:
nl.append(i)
print(sl, "is the list of string values.")
print(nl, "is the list of numerical values.")
b) Sorting the strings list in ascending order.
This is done with the view that it proceeds from the above coding. If not, a program will have to be made to create a list solely for string, something similar to the one above, excluding the numerical part.
sl.sort()
print(sl)
c) Adding an element 56.89 to the number list.
nl.append(56.89)
print(nl)
d) Replacing the element "Speakers" to "Headphones".
sl.replace("Speakers", "Headphones")
print(sl)
e) Deleting the second element of the numbers list.
del nl[1]
print(nl)
f) Displaying the modified strings and number lists.
print(sl, "is the new list of strings.")
print(nl, "is the new list of numbers.")
#LearnWithBrainly
#BrainlyFast
(。・∀・)ノ