Re: problem with sorting

2008-03-28 Thread jwelby
On Mar 28, 5:38 am, [EMAIL PROTECTED] wrote:
  dict = {'M':3, 'R':0, 'S':2}
  print dict

 {'S': 2, 'R': 0, 'M': 3}

 now if I wanted sorted values in list, i am not able to do this print 
 dict.values().sort()

 None

 it returns None instead of [0, 2, 3]

The sort method works by sorting 'in place'. That means it doesn't
return the sorted value, but just sorts the sequence.

 t = {'M':3, 'R':0, 'S':2}
 x = t.values()
 x.sort()
 x
[0, 2, 3]

or you can use sorted(), which does return the sorted sequence:

 sorted(t.values())
[0, 2, 3]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a good Python environment

2007-11-10 Thread jwelby
On Nov 7, 12:42 pm, Colin J. Williams [EMAIL PROTECTED] wrote:
 jwelby wrote:
...

  I currently use Python Scripter as a lightweight editor for Windows.

 Could you elaborate on lightweight
 please? I find PyScripter to be a
 powerful editor/debugger combination.

 What functionality does Eclipse have
 that PyScripter does not?

 Colin W.


This is a fair question. I didn't phrase my post too well.

I find PyScripter does pretty much everything I need in terms of doing
actual development for Python. My use of 'lightweight' is by no means
a criticism of PyScripter - it's more of a compliment, as it refers to
the relatively modest demands that it makes on my system compared with
Eclipse, which can be hog.

The main reason I have used Eclipse for larger, team based, projects
is for the source control plug-ins. Eclipse has plug-in support for
cvs and svn. PyScripter may have this too - perhaps I've missed it.
(I'm away from my Windows box at the moment, otherwise I would check).
Of course, there are other ways to implement source control without it
needing to be integrated in the IDE, so even this need not put off
anyone who wants to use PyScripter with source control.

Summary - unless you need the added flexibility offered by Eclipse
plug-ins, PyScripter is a great tool for developing with Python on
Windows.


  For project work I use Eclipse, which can be installed with PyDev and
  other useful plug-ins already included if you choose a suitable
  distribution of Easy Eclipse (http://www.easyeclipse.org/). There is a
  distribution specifically for Python development, and also one for
  LAMP, which includes a number of other components which will be of use
  if you are developing for the web.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a good Python environment

2007-11-07 Thread jwelby
On Nov 6, 10:56 pm, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:
 Hey, I'm looking for a good Python environment. That is, at least an
 editor and a debugger, and it should run on Windows. Does anyone have
 any idea?

I currently use Python Scripter as a lightweight editor for Windows.

For project work I use Eclipse, which can be installed with PyDev and
other useful plug-ins already included if you choose a suitable
distribution of Easy Eclipse (http://www.easyeclipse.org/). There is a
distribution specifically for Python development, and also one for
LAMP, which includes a number of other components which will be of use
if you are developing for the web.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python on window

2007-03-23 Thread jwelby
On Mar 23, 7:25 am, sandeep patil [EMAIL PROTECTED] wrote:
 i have install python on window xp os.
 C:/program files/python

 i have done print program it working but .py can't  working
  help me  to how i will execute this file this file where i will save
 it.
 path execution how .
 tell me about any envorment veriable in python to set before python
 editor run,it path. etc
 

  print ' sandeep patil'
  sandeep patil
  print ' sandeep bhagwan  patil ,msc. java j2ee developer

 SyntaxError: EOL while scanning single-quoted string print ' sandeep 
 bhagwan  patil ,msc. java j2ee developer'

  sandeep bhagwan  patil ,msc. java j2ee developer

  import posix

 Traceback (most recent call last):
   File pyshell#4, line 1, in module
 import posix
 ImportError: No module named posix

  phonebook = {'sandeep':9325,'amit':9822,'anand':9890}
  phonebook = {'titu':9423,'dadu':9422,'giri':9326}
  inverted_phonebook=invert(phonebook)

 Traceback (most recent call last):
   File pyshell#7, line 1, in module
 inverted_phonebook=invert(phonebook)
 NameError: name 'invert' is not defined def invert(table):

 index={}
 for key in table.key():
 value=table[key]
 if not index.has_key(value):
 index[value]=[]
 index[value].append(key)
 return index
 

Hi Sandeep.

As you are working with Python on Windows, I would suggest that you
install the Python for Windows extensions from here:

http://sourceforge.net/project/showfiles.php?group_id=78018

It includes a very good application called PythonWin. Once installed,
PythonWin will be available under Python in your Start menu.

If you run PythonWin, File/New gives you the option to create a new
Python script. To begin with, you can save into the Lib folder of your
Python installation (probably C:\Python25\Lib). I usually add my
initials at the front of the script name to differentiate my scripts
from the standard ones if I put stuff in Lib.

You should be able edit your PYTHONPATH variable in PythonWin - see
the Tools options (though, now I look, my installation actually has a
bug in this function), or alternatively, you can add a folder to your
PYTHONPATH environment variable in RegEdit (if you know what you're
doing).

I hope this helps.

J.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python on window

2007-03-23 Thread jwelby
That should have been:

You should be able edit your PYTHONPATH variable (should you need
to)...

Gabiel is right, it's not usually required.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: returning index of minimum in a list of lists

2006-06-21 Thread jwelby
def minIndexFinder(seq):
mins = []
listIndex = 0
result = []
for item in seq:
mins.append([listIndex,min(item),item.index(min(item))])
listIndex += 1
lowest = min([x[1] for x in mins])
for item in mins:
if item[1] == lowest:
result.append([item[0], item[2]])
return result

A bit more verbose, but maybe slightly more readable??

I probably should have used enumerate like Paul did.

For the index of the *first* (or only) occurence of the minimum value
in a list of numbers you can just use:

seq.index(min(seq))

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help removing list elements.

2006-04-29 Thread jwelby
This looks like a job for list comprehensions:

 returned_lines= ['Name: John, Value: 12','We don't want this one.','Name: 
 Eric, Value: 24']
 [x for x in returned_lines if ('Name' in x and 'Value' in x)]
['Name: John, Value: 12', 'Name: Eric, Value: 24']

List comprehensions are great. If you are not familiar with them, check
out the Python documentation. Once you get started with them, you won't
look back.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help removing list elements.

2006-04-29 Thread jwelby
Ooops!

Looking at your example a bit closer, change the 'and' in the list
comprehension I posted  to 'or', and it should do what you want.

-- 
http://mail.python.org/mailman/listinfo/python-list