def quick_sort(ls):
return [] if ls == [] else quick_sort([y for y in ls[1:] if y < ls[0]]) + [ls[0]] + quick_sort([y for y in ls[1:] if y >= ls[0]])
if __name__ == '__main__':
l1 = [3,56,8,1,34,56,89,234,56,231,45,90,33,66,88,11,22]
l2 = quick_sort(l1)
print l1
print l2
Script is to use a particular description language, based on the format of a certain executable file, also called macro or batch file. At the same time, "script" is the term writer term, the story form is called the script.
星期六, 八月 14, 2010
python3.0 dictionary key order
In fact, the dictionary object that is key - the value of the following is a dictionary object to add, modify, delete (modify and add the same way, when the key does not exist when the value added)
IDLE 3.0
>>> Dic = ("aa": 1, "bb": 2, "ab": 3)
>>> Dic
('Aa': 1, 'ab': 3, 'bb': 2)
>>> For k in sorted (dic.keys ()):
print (k)
aa
ab
-----------------------------------------------
In fact, the dictionary object that is key - value pairs
The following is a dictionary object to add, modify, delete
(Modify and add the same way, when the key does not exist when the value added)
>>> Dic ["cc"] = 4
>>> Dic
('Aa': 1, 'cc': 4, 'ab': 3, 'bb': 2)
>>> Dic ["bc"] = 5
>>> Dic
('Aa': 1, 'cc': 4, 'ab': 3, 'bb': 2, 'bc': 5)
>>> Dic ["cc"] = 6
>>> Dic
('Aa': 1, 'cc': 6, 'ab': 3, 'bb': 2, 'bc': 5)
>>> Del dic ["cc"]
>>> Dic
('Aa': 1, 'ab': 3, 'bb': 2, 'bc': 5)
IDLE 3.0
>>> Dic = ("aa": 1, "bb": 2, "ab": 3)
>>> Dic
('Aa': 1, 'ab': 3, 'bb': 2)
>>> For k in sorted (dic.keys ()):
print (k)
aa
ab
-----------------------------------------------
In fact, the dictionary object that is key - value pairs
The following is a dictionary object to add, modify, delete
(Modify and add the same way, when the key does not exist when the value added)
>>> Dic ["cc"] = 4
>>> Dic
('Aa': 1, 'cc': 4, 'ab': 3, 'bb': 2)
>>> Dic ["bc"] = 5
>>> Dic
('Aa': 1, 'cc': 4, 'ab': 3, 'bb': 2, 'bc': 5)
>>> Dic ["cc"] = 6
>>> Dic
('Aa': 1, 'cc': 6, 'ab': 3, 'bb': 2, 'bc': 5)
>>> Del dic ["cc"]
>>> Dic
('Aa': 1, 'ab': 3, 'bb': 2, 'bc': 5)
Python Developer Activex component method
Python strong feature is that it omnipotent.
Use the win32com module development window ActiveX example: (If you have not installed win32com module, then go to http://python.net/crew/skippy/win32/Downloads.html download).
# SimpleCOMServer.py
class PythonUtilities:
_public_methods_ = ['SplitString']
_reg_progid_ = "Python.Utilities"
_reg_clsid_ = "(A6688635-62F5-41cb-AF54-CBA84C2F0F86)"
def SplitString (self, val):
return "Hello world", val
if __name__ == '__main__':
print "Registering COM server ..."
import win32com.server.register
win32com.server.register.UseCommandLine (PythonUtilities)
In the console run: python SimpleCOMServer.py
In the HTML page to call the Activex component:
window.onload = function () (
var obj = new ActiveXObject ("Python.Utilities");
alert (obj.SplitString ("Hel"));
)
Use the win32com module development window ActiveX example: (If you have not installed win32com module, then go to http://python.net/crew/skippy/win32/Downloads.html download).
# SimpleCOMServer.py
class PythonUtilities:
_public_methods_ = ['SplitString']
_reg_progid_ = "Python.Utilities"
_reg_clsid_ = "(A6688635-62F5-41cb-AF54-CBA84C2F0F86)"
def SplitString (self, val):
return "Hello world", val
if __name__ == '__main__':
print "Registering COM server ..."
import win32com.server.register
win32com.server.register.UseCommandLine (PythonUtilities)
In the console run: python SimpleCOMServer.py
In the HTML page to call the Activex component:
window.onload = function () (
var obj = new ActiveXObject ("Python.Utilities");
alert (obj.SplitString ("Hel"));
)
订阅:
博文 (Atom)