Re: problem with Sorting from Array

2011-02-02 Thread Chris Rebert
On Wed, Feb 2, 2011 at 10:30 PM, shanti bhushan
 wrote:
> Dear All,
>
> funtion "textPosValue " will give me key ,type and pos values from the
> arrays.
> This an embedded application code .
> I want to execute some thing when key ==0 && type ==0 please let me

>                if (key ==0 && type ==0)                                 // i 
> want

The logical-AND operator in Python is spelled "and", not "&&" as in
C-like languages.
Also, comments start with a "#", not with "//" (though you probably
already know this and seem to have merely had a momentary lapse).

I can offer no definitive guidance as to where the conditional belongs
due to your code's purpose being rather opaque. I would hazard a guess
that it should go near where you change the values of `key` and `type`
(since the condition depends upon them) and outside of any nested loop
(since you mentioned nothing about repetition).

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


problem with Sorting from Array

2011-02-02 Thread shanti bhushan
Dear All,

funtion "textPosValue " will give me key ,type and pos values from the
arrays.
This an embedded application code .
I want to execute some thing when key ==0 && type ==0 please let me
know
where to put such code i am getting confused with it


def textPosValue(data):
str_arr1=[" 0",".@/:1","abc2",
   "def3","ghi4",
   "jkl5","mno6",
   "pqrs7","tuv8",
   "wxyz9" ]
str_arr2=[" 0",".@/:1","ABC2",
   "DEF3","GHI4",
   "JKL5","MNO6",
   "PQRS7","TUV8",
   "WXYZ9" ]
str_arr3=["0","1","2",
 "3","4","5",
 "6","7","8",
 "9" ]
str_arr4=[" 0",".@/:1","?[] 2",
   "!<> 3",",&\ 4",
   "()~ 5","'{}` 6",
   ";$|^ 7","_#% 8",
   "-*+=9" ]
str=[str_arr1,str_arr2,str_arr3,str_arr4]
k=1
first=0
SecPos=0
sts=0
try:
for first in range(4):
for SecPos in range(10):
#print "first,SecPos,str[first]
[Secpos]",first,SecPos,str[first][SecPos]
sts=str[first][SecPos].find(data)
#print sts
if (sts < 0):
   continue
else:
k=0
break
if (k==0):
print sts
break


return first, SecPos, sts
except IndexError:
return -1,-1,-1


for ch in "43.88.79.132" :
type,key,Pos=textPosValue(ch)
for i in range(type):
cat,data=remote_keypress("green")
send_sircs(cat,data)
sleep(0.5)

for j in range(Pos+1):
if (key ==0 && type ==0) // i 
want
to execute some thing when , key ==0 && type ==0 , is it the right
position??
cat,data=remote_keypress("space")
send_sircs(cat,data)
sleep(0.5)
cat,data=remote_keypress("violet")
send_sircs(cat,data)
sleep(0.5)

cat,data=remote_keypress(key)
send_sircs(cat,data)
sleep(0.5)
sleep(0.5)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with sorting

2008-03-28 Thread bearophileHUGS
Duncan Booth:
> Both this and raj's suggestion create a single sorted list. Your suggestion
> creates two lists: the unsorted one and a separate sorted one. In most
> cases the difference is probably insignificant, but if you have a *lot* of
> values it might make a difference.

The good thing of Python 3.0 is that it forces you to do the right
thing here :-)

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with sorting

2008-03-28 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

> On Mar 28, 1:57ÿam, raj <[EMAIL PROTECTED]> wrote:
>> To ankit:
>>
>> Well, sort() doesn't return the sorted list. It returns None. Why not
>> this straightforward way?
>> dvals = dict.values()
>> dvals.sort()
>> print dvals
> 
> Why not sorted( dict.values() ).
> 

If you are going to do it that way then it may be preferable to use 
itervalues:

   print sorted(dict.itervalues())

Both this and raj's suggestion create a single sorted list. Your suggestion 
creates two lists: the unsorted one and a separate sorted one. In most 
cases the difference is probably insignificant, but if you have a *lot* of 
values it might make a difference.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with sorting

2008-03-28 Thread castironpi
On Mar 28, 1:57 am, raj <[EMAIL PROTECTED]> wrote:
> To ankit:
>
> Well, sort() doesn't return the sorted list. It returns None. Why not
> this straightforward way?
> dvals = dict.values()
> dvals.sort()
> print dvals

Why not sorted( dict.values() ).

Can it return the right things from the right things in order from the
givens?  ( dvals , values, sort, print ).decode()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with sorting

2008-03-28 Thread raj
To ankit:

Well, sort() doesn't return the sorted list. It returns None. Why not
this straightforward way?
dvals = dict.values()
dvals.sort()
print dvals
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with sorting

2008-03-27 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: problem with sorting

2008-03-27 Thread Paddy
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]

Try:

from pprint import pprint as pp
pp(my_dict)


It works well for other built-in types too.

P.S it is not good to use a name, dict, that already has a use in
Python.

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


problem with sorting

2008-03-27 Thread ankitks . mital
>>> 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]

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