Slicing of list

11 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 friends. So today in this video we'll be starting with slicing and list. So we have already done how to create a list and how to index a list. In this video, we'll be doing slicing a list. So we can also call out a few items from a list. So let's say we would like to just bring the middle item of a list.

So let me first create a list and then I'll tell you what slicing of a list mean. So I'll create a list with the name item. So item is equal to within a third bracket and right so here and right within quotes, people can rubber book Be nice blue. So, suppose these are a few items that is stored in the name of item created a list with the name item and dessert seven individual item individual thing that is stored in this variable called item. So just run this code Shift Enter and not print it print item. So, it displays perfectly.

Now if I want to view a part of this list, then what we can do, we can do slicing with slice. We can call multiple values by creating a range of index number separating via Kowloon that is If I write here, print and within print have to give the list name. So list name is item, then I have to provide the index number that is from portion to which portion I want to display. Suppose I want to display the rubber book and copy, then what I have to do, I've always told you that indexing of a pie from Titans start from zero. So this one is zero, this one is one, this one is two. So starting from 234, okay, so I give here to then column then five, why have given five because up to five it will give that is before five, it will print the values.

So here five means anything before five, it will be printed. So the fifth element will not be printed. So I've written five. So now printed, see, what do you got rubber book and copy. So, rubber is the index number with 210 book with index number three and then copy within this number four, always remember the number that you providing here means it will display the n minus one value that is if you provide five years it will display in minus one that is four that is index four here, if you write six over here, then it will display in minus one that is five six minus one that is the fifth index but it will print. So, any number that you provide here is the number it will display the number index number before that.

Now here what we are doing is we are creating a slice. Suppose here to is two five, the first index number is where the slide starts. That is too from here and the slides will start that is from index to the slicing will start and the second index number is when the slicing ends. This one is where the slicing ends, which is why in our example, the item at position 234 are the item that prints out. Okay, I think it's very clear to you now now if we want to include either end of the list, we can omit one of the number of 10 list. So if I want anything, so starting from the index number two, I want all the elements.

So what we can do is we can just omit the ending position then it will print all the available item available values after index number two, so just try it once. So print item then within this square bracket Write three is to and then provide nothing give blank over there what it will do is it will print all the values all the items starting from index number two. So from rubber it printed up to glue. Now if you want to print anything that is up to index number three, then what you can do so right print item here first give a colon so do not write anything for the starting position, write the ending position over here. So here I'll write three ceramic. See paper pen rubber is printed, so 012 is printed index number.

So here in slicing we can also use the negative index number, you have learned about the negative negative index number in our previous video. So here we'll be using that. So print it and then a square bracket. Give Kowloon and write minus two what it will print. Can you tell me run it and see what it does. So it prints all the number up to minus two that is this one is minus one that is blue and this one is minus two.

So up to this copy it printed everything starting from the beginning. Again if you write print item now now provide anything in the beginning so minus one is two, if nothing so what it will print, see what it prints, it prints only blue that is the last item, because here, this is the first item and this is the last item. Now I'll give a range with the negative index. So print item. Now here I provide the range that is minus five to minus So now run it, what it prints, it prints rubber book copy, because start counting from here minus five. So minus one minus two minus three minus four minus five.

So start counting from your rubber. Rubber is the Lynbrook book, then copy copies. So I've already told you this one means any value before that, so knife with index number minus two, so it will print the value just before that up to that value it will print now. So one last parameter that we can use with slicing is called stright, which refers to how many items to move forward after the list of the first item is retrieved from the list. So we have omitted the stripe parameter and Python defaults to the stride of one so that if Identify between two index number is retrieved the syntax for this construction is write the name that is listening I did and then write one is to find and then provide here one more value here provide to then what will happen so basically what we should do here is we should write it within square brackets basically so before this right print, okay now run it What happened?

See what happened starting from one to fifth, it took two element one to fit that is 012345 that is from when it started, and then it printed on to item 10 and book why because this too The value to hear here tells Titan to print every other item that is starting from pen up to knife, it will print every other item omitting one item in between that is it will print pen, then it will omit rubber again it will print book again it will omit copy and then if I providing the range then it will in print knife. So, here and provided up to five. So, it will print up two copies. So, within this copy, only one item can be dropped that is rubber. So pen and book is print in between these two value Robert is dropped, again copies dropped. So if I provide a larger range suppose if I remove this five and provide seven over here, so what it will print, it prints pen book knife, why?

So starting from the first index, this is index one, so one, it will omit the next number. Then it will print the third one Then again it will omit the next index, then it will again print the next item. So it will go on omitting one value after each print. So the stride value of two tells the program to print out only every other item. So we can omit the first two parameters and use strike alone as a parameter with a syntax like this. So print item.

Now just don't write the force to index value. So I'll just provide them semi colons, and then right to what it will print, it will print every other item starting from the first position paper, then it will print travel, then it will print copy and then it will print blue. So what it print, paper rubber copy you see every other item is printed here. So by printing out the list item with a stripe set of two, only four values are printed, so slicing list with both positive and negative index number and indicating stripe providers with the control to manipulate list and receive the output we are trying to achieve. So in this video we have learned about slicing and how to use the stright option with the list indexing. So see you in the next video.

Till then keep practicing. 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.