Modifying Lists in Python
#1. Create a list called "components" and populate it with a number (minimum 5) of mechatronics components. Print each item (component) by accessing each #
#element in the list, one at a time. This would be a good application for experimenting with a FOR loop
components = ['resistor', 'capacitor', 'motor', 'wire', 'relay']#create a list
for component in components:#This loop will go through all the elements creating a new variable that gets printed in every iteration
print(component.title())
#2. Utilizing the same list as in 1. instead of printing the item in each element, print a message using each element in the list.
#The text of each message should be the same but each message should utilize a different element.
for component in components:#This time the new variable is added to a string before being printed.
print(f"{component.title()} is part of the mechatronics in this device.")
#3. Create a list of your own using a minimum of 6 elements. Print a unique message for each element, using the element in the text.
animals=['dogs','cats','fish','turtles','birds','snakes',]
for pets in animals:
print(f"{pets.title()} can be purchased at Petco.")
#4. Add an element to your list using the appropriate method()
animals.append('hamsters')#adds an item at the end of the list
print(animals)
#5. Remove an element using the appropriate method()
animals.remove('snakes')#permanently removes the string form the list
print(animals)
#6.Remove an element from your list and place it in a separate variable
new_pet = animals.pop()#"pops" an element from the list
print(new_pet)#new variable
print(animals)
#7.Put the "popped" out element back into your list after having printed it with a personal message
print(f" The element {new_pet.title()} was 'popped' from the list." )
animals.append(new_pet)
print(animals)
print(f" The element {new_pet.title()} was returned to the list." )
#8.Use del to remove all items from your list
del animals
animals=[]
#9.Print your empty list
print(animals)
#10. Create a new list with a minimum of 6 items
smart_phones= ['samsung','alcatel','motorolla','apple','nokia','sony','lg','htc']
#11. Print your list in its original order
print("This is original list:")
print(smart_phones)
#12.Use sorted() to print your list in alphabetical order without actually modifying the original list
print("\nThis is the sorted list:")
print(sorted(smart_phones))#temporarily sorts but returns the original variable
#13.Show that the list is still in its original order using print
print("\nBack to the original list again:")
print(smart_phones)
#14. Use sorted() to print your list in reverse alphabetical order without permanently altering your list
print(sorted(smart_phones, reverse=True))#temporary reversed list
#15. Print the original list to show that it was not permanently altered
print(smart_phones)
#16. Use reverse() to change the order of your list, print the list to show that it has changed
smart_phones.reverse()#reverses the unsorted original list
print(smart_phones)
#17.Use reverse() to change the order of your list again, print the list to show that its back to its original order
smart_phones.reverse()#reverses back to the original list
print(smart_phones)
#18. Use sort() to permanently store your list in alphabetical order. Print the list to verify
smart_phones.sort()#permanently sorts alphabetically
print(smart_phones)
#19. Use sort() to change your list so its stored in reverse alphabetical order. Print the list to show the change'
smart_phones.sort(reverse=True)#reverses the list permanentlycallsign.sort(reverse=True)
print(smart_phones)
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Modifying Lists in Python», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.