473,698 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

return the last item in a list


I've googled for the above and get way too many hits..

I'm looking for an 'easy' way to have the last item in a list returned.

I've thought about

list[len(list)-1]

but thought there would be a more gracefull way.

Jul 18 '05 #1
15 3641
On 30 Mar 2005 10:48:17 -0700, rumours say that David Bear
<Da********@asu .edu> might have written:
I've googled for the above and get way too many hits..

I'm looking for an 'easy' way to have the last item in a list returned.

I've thought about

list[len(list)-1]

but thought there would be a more gracefull way.


There is.

alist[-1]

Did you read the tutorial? This is referenced in "3. An Informal
Introduction to Python".
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
Jul 18 '05 #2
[David Bear]
I'm looking for an 'easy' way to have the last item in a list returned.


Try mylist.pop() or mylist[-1].
Raymond Hettinger
Jul 18 '05 #3
Raymond Hettinger wrote:
I'm looking for an 'easy' way to have the last item in a list returned.


Try mylist.pop() or mylist[-1].


Note that list.pop also removes the last element from the list in the
process.

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Granted that I must die, how shall I live?
-- Michael Novak
Jul 18 '05 #4
Hi. I have small problem. I need to load extension module that depends
on shared library. Before actually importing module I tried to edit
os.environ or to call directly to os.putenv without any success -
shared library was not found. I tried to search the Internet for the
answer. The only approach I saw was to set LD_LIBRARY_PATH before
invoking python script. I don't like this solution.

Roman
Jul 18 '05 #5
What OS? Linux? Solaris?

J

Roman Yakovenko wrote:
Hi. I have small problem. I need to load extension module that depends
on shared library. Before actually importing module I tried to edit
os.environ or to call directly to os.putenv without any success -
shared library was not found. I tried to search the Internet for the
answer. The only approach I saw was to set LD_LIBRARY_PATH before
invoking python script. I don't like this solution.

Roman

Jul 18 '05 #6
On Mar 31, 2005 9:20 AM, John Abel <jo*******@pa.p ress.net> wrote:
What OS? Linux? Solaris?
Does it matter? If so, please explain why ( lack of knowledge )
I am using Linux ( Debian Surge )

Thanks

J

Roman Yakovenko wrote:
Hi. I have small problem. I need to load extension module that depends
on shared library. Before actually importing module I tried to edit
os.environ or to call directly to os.putenv without any success -
shared library was not found. I tried to search the Internet for the
answer. The only approach I saw was to set LD_LIBRARY_PATH before
invoking python script. I don't like this solution.

Roman

Jul 18 '05 #7
With Solaris 8+ you would use the command crle, with Linux
(RedHat/SuSE/Mandrake) you need to add the relevant directories
/etc/ld.so.conf and run ldconfig. I've not got a Debian box to hand, so
I can't say if it matches, but that should give you a pointer.

HTH

J

Roman Yakovenko wrote:
On Mar 31, 2005 9:20 AM, John Abel <jo*******@pa.p ress.net> wrote:

What OS? Linux? Solaris?


Does it matter? If so, please explain why ( lack of knowledge )
I am using Linux ( Debian Surge )

Thanks

J

Roman Yakovenko wrote:
Hi. I have small problem. I need to load extension module that depends
on shared library. Before actually importing module I tried to edit
os.environ or to call directly to os.putenv without any success -
shared library was not found. I tried to search the Internet for the
answer. The only approach I saw was to set LD_LIBRARY_PATH before
invoking python script. I don't like this solution.

Roman



--
*John Abel
Senior Unix Administrator*
PA News Limited
www.pa.press.net <http://www.pa.press.ne t>
E-Mail address: jo*******@pa.pr ess.net <mailto:jo***** **@pa.press.net >
Telephone Number : 01430 455553
Fax Number : 0870 1240192
Mobile Number : 07971 611356
The Bishop's Manor, Market Place, Howden, DN14 7BL
PA News Limited, 292 Vauxhall Bridge Road, London SW1V 1AE. Registered
in England No. 3891053.
Jul 18 '05 #8
Thanks for help. But it is not exactly solution I am looking for. I
would like to do it from python script. For example

update_env() #<- this function will change LD_LIBRARY_PATH
import extension_that_ depends_on_shar ed_library

Roman

On Mar 31, 2005 9:35 AM, John Abel <jo*******@pa.p ress.net> wrote:
With Solaris 8+ you would use the command crle, with Linux
(RedHat/SuSE/Mandrake) you need to add the relevant directories
/etc/ld.so.conf and run ldconfig. I've not got a Debian box to hand, so
I can't say if it matches, but that should give you a pointer.
I think I should have permissions to do it. (more over users of my
scripts should have permissions )
HTH

J

Roman Yakovenko wrote:
On Mar 31, 2005 9:20 AM, John Abel <jo*******@pa.p ress.net> wrote:

What OS? Linux? Solaris?


Does it matter? If so, please explain why ( lack of knowledge )
I am using Linux ( Debian Surge )

Thanks

J

Roman Yakovenko wrote:

Hi. I have small problem. I need to load extension module that depends
on shared library. Before actually importing module I tried to edit
os.environ or to call directly to os.putenv without any success -
shared library was not found. I tried to search the Internet for the
answer. The only approach I saw was to set LD_LIBRARY_PATH before
invoking python script. I don't like this solution.

Roman



--
*John Abel
Senior Unix Administrator*
PA News Limited
www.pa.press.net <http://www.pa.press.ne t>
E-Mail address: jo*******@pa.pr ess.net <mailto:jo***** **@pa.press.net >
Telephone Number : 01430 455553
Fax Number : 0870 1240192
Mobile Number : 07971 611356
The Bishop's Manor, Market Place, Howden, DN14 7BL
PA News Limited, 292 Vauxhall Bridge Road, London SW1V 1AE. Registered
in England No. 3891053.

Jul 18 '05 #9
Roman Yakovenko wrote:
Hi. I have small problem. I need to load extension module that depends on shared library. Before actually importing module I tried to edit
os.environ or to call directly to os.putenv without any success -
shared library was not found. I tried to search the Internet for the
answer. The only approach I saw was to set LD_LIBRARY_PATH before
invoking python script. I don't like this solution.


Looks like it's glibc linker inflexibility:
http://hathawaymix.org/Weblog/2004-12-30
"""
There is no provision for modifying the library search path once your
program has started.
"""

Python does update enviromental variables if you change os.environ or
call os.putenv, but the linker ignores the changes.

Serge.

Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
4138
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open Source" manner, and in an attempt to build a ground-swell of support to convince the folks at Microsoft to add it. Proposal: "first:" "last:" sections in a "foreach" block The problem: The foreach statement allows iterating over all the...
12
4124
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport) {
10
14436
by: tkpmep | last post by:
For any list x, x.index(item) returns the index of the FIRST occurrence of the item in x. Is there a simple way to identify the LAST occurrence of an item in a list? My solution feels complex - reverse the list, look for the first occurence of the item in the reversed list, and then subtract its index from the length of the list - 1, i.e. LastOcc = len(x) - 1 - x.index(item) Is there a simpler solution?
0
1666
by: inandout | last post by:
Hi, I was wondering if anyone can help me with this. I have a listview that is specified to a size of: 348W x 308H When items are added to it, no problems. However when items continue to be added such that the list gets too large to be displayed, the scrollbars appear. Once this occurs, the last item though selected and focused (highlighted blue), will not appear within the viewable area since the listview requires a scrolldown. This...
23
18068
by: Florian Lindner | last post by:
Hello, can I determine somehow if the iteration on a list of values is the last iteration? Example: for i in : if last_iteration: print i*i else:
15
2865
by: buddhatown | last post by:
Very simple question for all you folks out there. I am total noob with js. I have a list called drawPathList thats just a list of xy coordinates. I use this to construct a drawing on a map. However, people would like to be able to 'Undo' something that they have drawn, so I'd like to yank that last item in a given list. drawPathList looks like this: 23,34||45,67||456,678||43,78 Can someone help me with a function to remove the...
4
3931
by: z060053 | last post by:
#include <iostream> using namespace std; template <class T>class list{ protected: typedef struct node{ node* prev; T* data; node* next; }; node* first;
5
15595
by: dudeja.rajat | last post by:
Sorry : Earlier mail had a typo in Subject line which might look in-appropriate to my friends Hi, I've a list some of whose elements with character \. I want to delete this last character from the elements that have this character set at their end,
0
1135
by: Fredrik Lundh | last post by:
dudeja.rajat@gmail.com wrote: explicitly comparing against true is bad style; better write that as if item.endswith('\\'): item.endswith("\\") works just fine:
0
8680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9030
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.