Re: [Tutor] Sorting Data in Databases

2009-11-23 Thread Ken G.
Che M wrote: Ken, I would also recommend trying out databases, if you have an interest. I found them a fun new aspect of using Python. I would recommend using SQLite, which very conveniently comes with Python. Alan Gauld's tutorial that you've read part of has a nice section on Working w

Re: [Tutor] R?p. : Sorting Data in Databases

2009-11-23 Thread Ken G.
Albert Sweigart wrote: Ken, You should probably use the sorting functionality that your DBMS provides. However, if you have a list of strings that end with a new line and start with an apostrophe, you can use list comprehensions to remove them: newlist = [x[1:-1] for x in newlist] You can look

Re: [Tutor] Sorting Data in Databases

2009-11-23 Thread Che M
Ken, I would also recommend trying out databases, if you have an interest. I found them a fun new aspect of using Python. I would recommend using SQLite, which very conveniently comes with Python. Alan Gauld's tutorial that you've read part of has a nice section on Working with Databases,

Re: [Tutor] understanding the behavious of parameter 'key' in sort

2009-11-23 Thread Lie Ryan
Shashwat Anand wrote: I intended to sort a list which sorts according to user-defined custom sorting-order. For example: If sorting-order is "zabc...wxy", then the output will be in lexicographically sorted order but z will always be given priority over rest others. as a test case i took sortin

Re: [Tutor] R?p. : Sorting Data in Databases

2009-11-23 Thread Albert Sweigart
next part -- > An HTML attachment was scrubbed... > URL: > <http://mail.python.org/pipermail/tutor/attachments/20091123/fb03a325/attachment.htm> > > -- > > ___ > Tutor maillist  -  tu

[Tutor] understanding the behavious of parameter 'key' in sort

2009-11-23 Thread Shashwat Anand
I intended to sort a list which sorts according to user-defined custom sorting-order. For example: If sorting-order is "zabc...wxy", then the output will be in lexicographically sorted order but z will always be given priority over rest others. as a test case i took sorting order as reverse of norm

Re: [Tutor] Rép. : Sorting Data in Databases

2009-11-23 Thread Ken G.
Luhmann wrote: I'd suggest you load all your data into a list of lists, then use the .sort() method to sort it. The sort method takes a key= argument, which should be a function that does some transformation to your data, then returns something to be compared. for instance: >>> l=[[1,2,3],[

Re: [Tutor] Python 3.1: How to print a very large number to n significant digits?

2009-11-23 Thread Richard D. Moores
On Mon, Nov 23, 2009 at 12:23, Wayne Werner wrote: > On Mon, Nov 23, 2009 at 12:28 PM, Richard D. Moores > wrote: >> >> Can't find the answer in the docs for 3.1 >> >> To print 123**34.6 to 5 sig digits, >> >> print("%.*e" % (4, 123**34.6)) >> >> will do the job: >> >> >>> print("%.*e" % (4, 123*

Re: [Tutor] Python 3.1: How to print a very large number to n significant digits?

2009-11-23 Thread Wayne Werner
On Mon, Nov 23, 2009 at 12:28 PM, Richard D. Moores wrote: > Can't find the answer in the docs for 3.1 > > To print 123**34.6 to 5 sig digits, > > print("%.*e" % (4, 123**34.6)) > > will do the job: > > >>> print("%.*e" % (4, 123**34.6)) > 2.0451e+72 > > However, if the number is 123**346, using >

[Tutor] Python 3.1: How to print a very large number to n significant digits?

2009-11-23 Thread Richard D. Moores
Can't find the answer in the docs for 3.1 To print 123**34.6 to 5 sig digits, print("%.*e" % (4, 123**34.6)) will do the job: >>> print("%.*e" % (4, 123**34.6)) 2.0451e+72 However, if the number is 123**346, using print("%.*e" % (4, 123**346)) gets me >>> print("%.*e" % (5, 123**346)) Trace

Re: [Tutor] Iterable Understanding

2009-11-23 Thread Martin Walsh
Stephen Nelson-Smith wrote: > Martin, > >>def __iter__(self): >>while True: >>for logline in self.logfile: >>heappush(self.heap, (timestamp(logline), logline)) >>if len(self.heap) >= self.jitter: >>break >>try:

Re: [Tutor] (no subject)

2009-11-23 Thread OkaMthembo
Hi Mark, When i started off i had pretty much the same questions. I think you need to start with the Python tutorial as it will show you the basics (from the Python shell and how to write and run Python files, to language syntax + keywords and how to define and use functions, classes, modules etc)

Re: [Tutor] Sorting Data in Databases

2009-11-23 Thread spir
"Ken G." wrote: > I have not use the DBMS as I am unaware of them in both languages. DBMS is short for Data Base Management System, see wikipedia entry on the topic. Actually, the term is a bit ambiguous: * From a user point of view, a BDMS will be an application allowing managing data sets

Re: [Tutor] Iterable Understanding

2009-11-23 Thread Stephen Nelson-Smith
Martin, >    def __iter__(self): >        while True: >            for logline in self.logfile: >                heappush(self.heap, (timestamp(logline), logline)) >                if len(self.heap) >= self.jitter: >                    break >            try: >                yield heappop(self.he