Hi All,
I have a list of varying length. Would someone know the way to get the last
two values for this? I can see how this is done with a list that I know the
length of, but not one thats generated by user input.
Thanks for any help 8 1960
"M. Clift" <no***@here.com > wrote in message
news:cg******** **@news7.svr.po l.co.uk... Hi All,
I have a list of varying length. Would someone know the way to get the
last two values for this? I can see how this is done with a list that I know
the length of, but not one thats generated by user input.
Thanks for any help
"M. Clift" <no***@here.com > wrote in message
news:cg******** **@news7.svr.po l.co.uk... Hi All,
I have a list of varying length. Would someone know the way to get the
last two values for this? I can see how this is done with a list that I know
the length of, but not one thats generated by user input.
Thanks for any help
Use negative index values to count backwards from the end of a list or
tuple.
x = [ 0, 1, 2, 3, 4]
x[-1] gives 4
x[-2] gives 3
x[-2:] gives [3,4] <- this is called "slice" notation
You will find *many* more interesting and fun facts in the Python Tutorial.
-- Paul
MC> I have a list of varying length. Would someone know the way to get
MC> the last two values for this?
mylist[-2:]
Skip
Thankyou all for your help. Exactly what I needed : )
A negative index counts from the end, so:
l = [0,1,2,3,4]
l[-1] == 4
this works for slices too:
l[-2:] == [3,4]
On Thu, Aug 19, 2004 at 03:45:47AM +0100, M. Clift wrote: Hi All,
I have a list of varying length. Would someone know the way to get the last two values for this? I can see how this is done with a list that I know the length of, but not one thats generated by user input.
Thanks for any help
M. Clift wrote: Hi All,
I have a list of varying length. Would someone know the way to get the last two values for this? I can see how this is done with a list that I know the length of, but not one thats generated by user input.
Thanks for any help
M,
Note this, maybe, unexpected behavior: list=[1] list[-2:]
[1]
list = [] list[-2:0]
[]
wes
Again, thanks Wes, I appreciate it. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Navin |
last post by:
Ado Sort -Relate, Compute By, or Sort operations cannot be done on
column(s) whose key length is unknown or exceeds 10 KB.
hi,
guys
i have asp application running on iis 5.0 windows 2000
i use the ado sort property ......
shown below....
Rs.sort="person,lower_manager,lower_ccat_id,sac_name"
|
by: Brian Rivet |
last post by:
------=_NextPart_000_000E_01C34700.FE251100
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sorry, I'm a little new at this, here's the statement:
CREATE TABLE `TblUsers` (`UserId` INT(5) UNSIGNED DEFAULT NULL NOT NULL
AUTO_INCREMENT, `FirstName` VARCHAR(255) DEFAULT 'unknown' NOT NULL,
`LastName` VARCHAR(255) DEFAULT 'unknown' NOT NULL, `UserName`
|
by: John Salerno |
last post by:
Ok, I wrote this all by myself, which explains why it doesn't work. It
is meant to take a number and generate the next number that follows
according to the Morris sequence. It works for a single number, but what
I'd like it to do is either:
1. repeat indefinitely and have the number of times controlled elsewhere
in the program (e.g., use the morris() generator in a for loop and use
that context to tell it when to stop)
2. just make it...
|
by: TomServo |
last post by:
I am writing code that needs to run on a variety of Unix systems. I am
calling the statvfs and statfs system calls and I need to to convert some of
the integers returned to character strings. Normally I would do this using
sprintf as so:
sprintf(&buffer, "%lu", integer);
The problem is that I will not know if the integer values I am converting
are long or long long. I also do not know if the compilers being used will
support long long...
|
by: dba123 |
last post by:
I am getting the following error when a sub domain is receiving a shared
cookie:
I have this in both web.config of each application. The 1.1 application
does not have the decryption= value because you cannot have that for 1.1 or
asp.net will error out. The source application is coded in .NET 2.0 but the
target application that's sharing the source app's cookie is a .NET 1.1 app.
<machineKey...
| |
by: Anthra Norell |
last post by:
Hi,
I keep working around a little problem with unpacking in cases in which I don't know how many elements I get. Consider this:
def tabulate_lists (*arbitray_number_of_lists):
table = zip (arbitray_number_of_lists)
for record in table:
# etc ...
This does not work, because the zip function also has an *arg parameter, which expects an arbitrary length enumeration of arguments
|
by: SoFaraway |
last post by:
Hi all,
In C, to read a line from a file, we need to allocate some fixed length of memory first. However, if the line is longer than the length of the allocated memory, it can't be read correctly.
Does anyone have codes that can read in a line of unknown length?
Thank you very much!
|
by: Himanshu Chauhan |
last post by:
Hi!
I was wondering, In the first parse of a singly linked list of unknown
length, is it possible to know when we are at middle of the linked list?
Regards
--Himanshu
|
by: oldyork90 |
last post by:
I'm going thru code and have never seen this before
http://www.webreference.com/programming/javascript/mk/column2/3.html
Look at function CreateDragContainer() on line 25. It has no
arguments defined and depends on a function property named arguments
to process its input. I poked around and found this is deprecated.
How do you pass an unknown number of arguments to a function? Put
them in an array?
|
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...
|
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,...
| |
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |