Modifying a list

9 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.09
List Price:  €93
You save:  €27.90
£56.02
List Price:  £80.04
You save:  £24.01
CA$96.21
List Price:  CA$137.46
You save:  CA$41.24
A$106.50
List Price:  A$152.16
You save:  A$45.65
S$94.88
List Price:  S$135.55
You save:  S$40.67
HK$547.08
List Price:  HK$781.57
You save:  HK$234.49
CHF 63.59
List Price:  CHF 90.85
You save:  CHF 27.25
NOK kr764.52
List Price:  NOK kr1,092.22
You save:  NOK kr327.70
DKK kr485.54
List Price:  DKK kr693.66
You save:  DKK kr208.12
NZ$116.87
List Price:  NZ$166.97
You save:  NZ$50.09
د.إ257.07
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,696.46
List Price:  ৳10,995.41
You save:  ৳3,298.95
₹5,845.02
List Price:  ₹8,350.38
You save:  ₹2,505.36
RM331.92
List Price:  RM474.20
You save:  RM142.27
₦98,297.45
List Price:  ₦140,430.95
You save:  ₦42,133.50
₨19,467.44
List Price:  ₨27,811.82
You save:  ₨8,344.38
฿2,586.11
List Price:  ฿3,694.61
You save:  ฿1,108.49
₺2,257.70
List Price:  ₺3,225.42
You save:  ₺967.72
B$355.19
List Price:  B$507.43
You save:  B$152.24
R1,300.44
List Price:  R1,857.85
You save:  R557.41
Лв127.53
List Price:  Лв182.19
You save:  Лв54.66
₩95,343.18
List Price:  ₩136,210.38
You save:  ₩40,867.20
₪259.39
List Price:  ₪370.57
You save:  ₪111.18
₱4,014.38
List Price:  ₱5,735.07
You save:  ₱1,720.69
¥10,876.02
List Price:  ¥15,537.84
You save:  ¥4,661.82
MX$1,183.66
List Price:  MX$1,691.01
You save:  MX$507.35
QR254.83
List Price:  QR364.06
You save:  QR109.23
P952.42
List Price:  P1,360.66
You save:  P408.23
KSh9,168.69
List Price:  KSh13,098.69
You save:  KSh3,930
E£3,329.50
List Price:  E£4,756.64
You save:  E£1,427.13
ብር3,992.74
List Price:  ብር5,704.16
You save:  ብር1,711.42
Kz58,583.02
List Price:  Kz83,693.62
You save:  Kz25,110.60
CLP$65,554.03
List Price:  CLP$93,652.63
You save:  CLP$28,098.60
CN¥505.70
List Price:  CN¥722.46
You save:  CN¥216.76
RD$4,071.34
List Price:  RD$5,816.45
You save:  RD$1,745.10
DA9,415.49
List Price:  DA13,451.28
You save:  DA4,035.78
FJ$159.21
List Price:  FJ$227.46
You save:  FJ$68.24
Q544.84
List Price:  Q778.38
You save:  Q233.53
GY$14,671.19
List Price:  GY$20,959.74
You save:  GY$6,288.55
ISK kr9,784.60
List Price:  ISK kr13,978.60
You save:  ISK kr4,194
DH703.12
List Price:  DH1,004.51
You save:  DH301.38
L1,240.96
List Price:  L1,772.88
You save:  L531.91
ден4,012.27
List Price:  ден5,732.06
You save:  ден1,719.79
MOP$564.93
List Price:  MOP$807.08
You save:  MOP$242.14
N$1,294.05
List Price:  N$1,848.73
You save:  N$554.67
C$2,581.34
List Price:  C$3,687.79
You save:  C$1,106.44
रु9,369.68
List Price:  रु13,385.83
You save:  रु4,016.15
S/261.57
List Price:  S/373.68
You save:  S/112.11
K271.48
List Price:  K387.85
You save:  K116.36
SAR262.48
List Price:  SAR374.99
You save:  SAR112.51
ZK1,900.47
List Price:  ZK2,715.07
You save:  ZK814.60
L323.94
List Price:  L462.80
You save:  L138.85
Kč1,630.83
List Price:  Kč2,329.86
You save:  Kč699.02
Ft25,346.53
List Price:  Ft36,210.88
You save:  Ft10,864.35
SEK kr763.26
List Price:  SEK kr1,090.42
You save:  SEK kr327.16
ARS$61,644.55
List Price:  ARS$88,067.42
You save:  ARS$26,422.86
Bs483.68
List Price:  Bs691.01
You save:  Bs207.32
COP$273,058.61
List Price:  COP$390,100.45
You save:  COP$117,041.84
₡35,861.91
List Price:  ₡51,233.50
You save:  ₡15,371.58
L1,732.92
List Price:  L2,475.71
You save:  L742.78
₲523,307.77
List Price:  ₲747,614.58
You save:  ₲224,306.80
$U2,685.15
List Price:  $U3,836.09
You save:  $U1,150.94
zł280.89
List Price:  zł401.29
You save:  zł120.40
Already have an account? Log In

Transcript

Welcome to the second session. So today we'll be starting with modifying a list with operator so operator can be used to make modification to lists we'll look at using the plus and the star operator and their compound form of star n equal to add plus and equal two together. So the plus operator can be used to concatenate two or more lists together. So before using this operator, I need to create two different places. So I'll create a list with the name pet, where I just write few of the pets name. So dog get and then right, rabbit bored so these are the few elements that I'm storing in pet.

So print bit see Now I'll create one more list that will contain wild animals. So wild with the name, element, Tiger, lion or any fact again, for element I have written so print this. So this to list I have created Now I use this plus operator to concatenate these two lists into a single one. So I'm right animal and then I'll write pet class white, then print animal run. So if I now run this, I can see that two different lists is now concatenated. And it is now a single list.

So the list name that are provided first is the pet and then the wind. So the element of the pet least will be in the front and the element Have the whitelist will be in the back. So now we can also want getting it one, sorry two or more. Here I've used only two lists to concatenate. So you can use multiple lists to concatenate it into one. Now this plus operator can also add element to the list.

So if I want to add a few of the elements to the whitelist, then what we can do is I have to write a new listener, wild one. And now I'll write wild then use a plus sign and give few elements names. So here I'll write Fox, comma, monkey. So run it and now print this wild one. So see it has added Fox and monkey at the back of the end of the list. So in this way, you can add multiple elements to the existing list now Use the star operator now the star operator can be used to multiply in list so if you need to make a copies of all the files in the directory onto a server or share a playlist with friends, in this case, you need to multiply collection of data so let's multiply the white list by two and the pet list by three.

So I will write print white start to see it is repeating the melodies repeating the whole list together. So first it is writing diner land off an elephant then again it is repeating the all the values that is trying to land with an Elephant Elephant. So now if I want to multiply bed with three, then what happened? See it repeated three times. So dog, cat, rabbit, bird, dog, cat, rabbit. But in a game doc get a bit bored.

So, here it make copies of a particular list, the number that you will specify. Now we can also use compound form of the plus and the star operator with the assignment operator is equal to the plus and equal to and the star and equal to compound operator can be used to populate list in a quick and automated way. Now you can use this operator to fill in list with placeholders that you can modify at a later time with use user provided input. For example, if I want to add an item in the list wild, so this item will act as a placeholder and you'd add this placeholder item several times. To do this, we'll use the plus and equal to operator with a for loop. So we have already done for loop.

So here, I'll be using that for loop. So for x in range one comma four, right wild then plus equal to suppose you want to add a new item. Suppose I'll add zebra. Now print white. Now see what happened for each iteration of the for loop an extra list item of zebra is added to the origin list. So the first time when the list is running the for the first time for one, what happens here is there is added to the original list that is in the list tiger, Lion, Wolf and elephant was the original list.

So now zebra is added. Now the original list is modified with the five element. Now zebra is also a part of the list. Now the second time when the loop is running after zebra Against zebra is added. Now this Tuesday Bri is a part of this list and it became the original list. And now after this to zebra when the for loop is again learned running, then one more zebra is added.

So every time I run this, suppose if I increase the range to five, then what happened? See, it created one more list. And then again, one more zebra is added. So if you now want to change this value of zebra to anything, then that particular value will be added to the new list. Now this class and this is the function of class and the equal to operator and now what I'll do is I'll use this star and the equal to operator which behaves in a similar way so far. So create one leads to that is deer equal to within quotes right here.

Now here, one more time, I'll use a for loop. So for excellent range one comma four. Right dear start equal to to print dear now run it what happened just see it repeating the deer so many times because it forced repeating deer twice then four times and then eight times. So every time the loop is running it's starting repeat started repeating the value in a multiple way because you have written to so it will multiply with two, so two two into 244 into two eight, so eight times it is repeating the value. Now in the next part I will do how to remove an item from the list so item can be removed from list by using the Dell statement. This will delete the value of an entry index number is specified within the list so to delete an item, we need to specify the index number we have already done the index number.

So here we'll be using that index number and we will be deleting the elements from the list. So, if I want to delete an element from pet from the list pet, so, what I will do is I will write del then write the list name and then the provide the index number within the square bracket. So within the square bracket if I provide one what it will delete, it will delete item with index number one now first look at the pet list. So pet lists content dog cat, rabbit and boat. So the index number one means cat. So it should delete cat it should remove cat so run it and see cat is removed from the list so only dog rabbit and bird is present.

Now you can also remove a range of support that you need to provide a range then pet now here provided So I'm provides 123 and then print it, see, both this items is not deleted, and only left with one item that is talk. So in this way, you can delete a single item, as well as a range of items from a particular list by using this Dell function. So, the list data type is our flexible data time that can be modified throughout the course of your program. So the basic feature of least that is indexing, slicing, modifying and concatenate concatenating. A list is done now we'll be moving to the next data type that is tupple. So till then keep practicing.

See you in the next video. Thank you

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.