473,326 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Confused about a list.sort()

I have a list of numbers... actully I have two lists, List 1 is a list of
number strings and List2 is one of numbers.

List 1 example:
List1 = [ '20040124123000', '20040124123001', '20040125012456']

List 2 example:
List2 = [ 20040124123000L, 20040124123001L, '20040125012456L]

When I try either:
List1 = List1.sort ... or
List2 = List2.sirt

and then...
print List1... or
print List2

I get None.

Why is this?
How do I remedy this problem?
Jul 18 '05 #1
5 1509

"Amy G" <am*******@cox.net> wrote in message
news:S6FRb.2098$P17.1139@fed1read03...
I have a list of numbers... actully I have two lists, List 1 is a list of
number strings and List2 is one of numbers.

List 1 example:
List1 = [ '20040124123000', '20040124123001', '20040125012456']

List 2 example:
List2 = [ 20040124123000L, 20040124123001L, '20040125012456L]

When I try either:
List1 = List1.sort ... or
List2 = List2.sirt

and then...
print List1... or
print List2

I get None.

Why is this?
How do I remedy this problem?


Read the library reference manual on builtin objects - sequences - lists -
methods.

Seriously.

TJR


Jul 18 '05 #2
list.sort() sorts the list in-place; it doesn't return a new list.
Instead of "List1 = List1.sort()" just do "List1.sort()".

See the FAQ entry:
http://www.python.org/doc/faq/genera...he-sorted-list

-- David Goodger
Jul 18 '05 #3
On Tue, 27 Jan 2004 18:28:09 -0800, "Amy G" <am*******@cox.net> wrote:
I have a list of numbers... actully I have two lists, List 1 is a list of
number strings and List2 is one of numbers.

List 1 example:
List1 = [ '20040124123000', '20040124123001', '20040125012456']

List 2 example:
List2 = [ 20040124123000L, 20040124123001L, '20040125012456L]

When I try either:
List1 = List1.sort ... or
List2 = List2.sirt

and then...
print List1... or
print List2

I get None.

Why is this?


Yeah, most everyone who uses sort() for the first time gets bit by this.

Sort() sorts the list in place, and returns None:
list1=[20, 40, 60, 80, 10, 30, 50]
list1 [20, 40, 60, 80, 10, 30, 50] list1.sort()
list1

[10, 20, 30, 40, 50, 60, 80]

So, to sort list1, you just use list1.sort(), not foo = list1.sort()
Jul 18 '05 #4
Amy,
Switch from windoze to linux and provide screen dumps.

wes@linux:~> python
Python 2.3.3c1 (#3, Dec 26 2003, 16:36:50)
[GCC 3.3.1 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
list = [3,9,2]
list.sort()
list
[2, 3, 9]

Amy G wrote: I have a list of numbers... actully I have two lists, List 1 is a list of
number strings and List2 is one of numbers.

List 1 example:
List1 = [ '20040124123000', '20040124123001', '20040125012456']

List 2 example:
List2 = [ 20040124123000L, 20040124123001L, '20040125012456L]

When I try either:
List1 = List1.sort ... or
List2 = List2.sirt

and then...
print List1... or
print List2

I get None.

Why is this?
How do I remedy this problem?


Jul 18 '05 #5
On Wed, 28 Jan 2004 15:22:05 GMT, wes weston <ww*****@att.net> wrote:
Switch from windoze to linux and provide screen dumps.


I don't understand part of your comment. Windows can provide screen
dumps also. That's not a reason to switch. :-)
--dang
Jul 18 '05 #6

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

Similar topics

11
by: velthuijsen | last post by:
I tried taking a list and pass it through std::sort like the following: sort(Unsorted.begin(), Unsorted.end()); I got an error back stating that the list iterator doesn't have a binary...
1
by: Booser | last post by:
// Merge sort using circular linked list // By Jason Hall <booser108@yahoo.com> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> //#define debug
13
by: agentxx04 | last post by:
Hi. Our assignment was to creat a program that can find the average, median & mode of a #of integers. Here's my program: #include<stdio.h> int main() { int item; int a, b, t, mode; int...
2
by: Daniel | last post by:
I'm new to .Net and all of its abilities so I hope this makes sense. Basically I'm confused on when is the appropriate time to use web forms controls vs. regular HTML. For example in ASP...
12
by: aparnakakkar2003 | last post by:
can any one tell me if I give the followiing string in input: ABC abc BBC then how I can get ABC abc BBC
2
by: John Kelsey | last post by:
I am an old, longtime C programmer surprised and confused by an error message I'm getting from my VS2005 compiler... "Cannot pass 'Item' as a ref or out argument because it is a 'foreach...
2
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the...
36
by: pereges | last post by:
Hi, I am wondering which of the two data structures (link list or array) would be better in my situation. I have to create a list of rays for my ray tracing program. the data structure of ray...
3
by: raylopez99 | last post by:
This is an example of using multiple comparison criteria for IComparer/ Compare/CompareTo for List<and Array. Adapted from David Hayden's tutorial found on the net, but he used ArrayList so the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.