Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Last position of an object in list

How can I fetch the last position of an item in a list?
index() references the first position…
PHP Code

<?php 
my_list 
= [{},{},{}]

last = my_list[-1] 

¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´
Code
len(yourList) - 1

Pretty sure this works.


(Aug 19, 2021 02:23 AM)vorticalbox Wrote:  
PHP Code

<?php 
my_list 
= [{},{},{}]

last = my_list[-1] 

This returns the last item, not the index.
lel
(Aug 19, 2021 02:28 AM)SIM-888979 Wrote:  
Code
len(yourList) - 1

Pretty sure this works.



This returns the last item, not the index.

very good point I misread the OP

¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Release] by kunsDec 29, 2023 03:29 PM 0 147 Dec 29, 2023 03:29 PM
Last Post: kuns
[Release] by kunsDec 29, 2023 03:28 PM 0 135 Dec 29, 2023 03:28 PM
Last Post: kuns
[Python] by simmerDec 3, 2021 06:39 AM 4 177 Dec 3, 2021 06:39 AM
Last Post: simmer