0

Can anyone please solve this problem

c =['

#x27;,'£','€','\'] PY Use negative indexing to output the 4th value in the list print(c[])

12th Oct 2024, 4:30 PM
Sher Agha Hewadmal
Sher Agha Hewadmal - avatar
2 odpowiedzi
+ 3
Normally you index using c[0] or c[1], etc. Negative indexing lets you go from last to first. Just use negative numbers. c[-1] c[-2] etc. To extract the fourth item from a list with four items, it would be c[-1].
12th Oct 2024, 4:57 PM
Jerry Hobby
Jerry Hobby - avatar
0
Sher Agha Hewadmal normally you would simply use positive indexing to find the nth element from the left. The positive index would be n - 1. In this case n is 4, so that would be 4 - 1 = 3. It is easy to convert a positive index into a negative index. Subtract the length of the array from the positive index. In this case the array has 4 elements, so that would be 3 - 4 = -1. Here is a program I wrote where you can try it out: https://sololearn.com/compiler-playground/cAK8vNGOOZ9G/?ref=app
12th Oct 2024, 7:07 PM
Brian
Brian - avatar