Hello. Welcome to the 7th video of our Learning Python series. In our 6th video, we made sample question solutions by learning how to use strings - Strings. In this video, we will learn how to use lists and make sample question solutions. So let's start.
A value can be held in a variable. If you want to keep many values, which may be required in many programs, you can use the list structure. The list is expressed in square brackets and the values in it are separated by commas. For example, a = 5, variable a holds only one value. But the expression b = [1, 3, 5, 7, 9] is also a list and holds many values. To reach the values, the indices we learned in the previous strings course are used. It starts at 0 from left to right and continues as 1, 2, 3. From right to left, it starts from -1 and continues as -2, -3. For example, b [2] returns 5 and b [-2] returns 7 for sequence b. A list can contain different types of values.
With the 1:23 len function, the number of elements in the list can be learned. For example, the list of colors includes rainbow colors. Let our program take the colors in the list of colors one by one and write down one after another.
2:25 An empty list can be created and the list can be filled in the program. The append method is used to add elements to the list. Let's write a program. In this program, first enter a number and then enter as many more as this number. Let's add these numbers to the list and finally print the list.
3:38 The two lists can be combined with the + sign.
4:00 When a list is multiplied by a number, the number is duplicated.
4:18 Split and join methods
6:50 Slicing
List Methods
8:10 in, not in
8:52 len
8:55 max, min, sum
9:05 index
9:18 count
9:30 append
9:42 del
9:50 clear
10:00 copy
10:07 insert
10:32 pop
10:56 remove
11:09 reverse
11:14 sort
11:33 bool
11:45 We can also create a list with a certain number of elements. For example, the structure a = [0] * 5 can be used to create a list of 5 elements containing 0 values.
12:05 The following code can be used to create a list of five random numbers (numbers 1 to 10).
Question Solutions
12:45 1. Those older than the previous
Write the program that gives the numbers larger than the previous one from the numbers on the given list.
13:35 2. The largest number and index
Write the program that finds the largest number in the given list and the index of that number. If there is more than one of the largest number, it will return the first number.
14:55 3. Number of different elements
In an ascending order, write the program that finds out how many different numbers are available.
15:49 4. Displacement of maximum and minimum numbers
In the list with all elements different, write the program that replaces the maximum and minimum numbers.
16:55 5. Delete element
Write the program that deletes the k-indexed element from the list provided. The numbers to the right of the deleted element will be shifted to the left.
18:40 6. Adding elements
Write the program that adds the number a to the given index in the given list. The added element and all elements to its right will be shifted to the right one by one.