易截截图软件、单文件、免安装、纯绿色、仅160KB

python算法实践2 shell排序

#shell排序
def ShellPass(mylist, d):
size = len(mylist)
i = d
while i < size:
if mylist[i] < mylist[i - d]:
tmp = mylist[i]
j = i - d
mylist[j + d] = mylist[j]
j = j - d
while j >= 0 and mylist[j] > tmp:
mylist[j + d] = mylist[j]
j = j - d
mylist[j + d] = tmp
i = i + d
def ShellSort(mylist):
n = len(mylist)
while n > 1:
n = n // 3 + 1
ShellPass(mylist, n)

mylist0 = [12, 11, 13, 1, 2, 4, 3, 77, 44]
ShellSort(mylist0)
print(mylist0)
 


相关文档:

python 如何返回多个值

如何写一个返回多个值的函数
函数的return 语句只能返回一个值,可以是任何类型。
因此,我们可以“返回一个 tuple类型,来间接达到返回多个值
”。
例:   x 除以 y 的余数与商的函数
def    F1 ( x, y ):
         a = x % y
  ......

python字符串使用总结



来源:
作者:
灵剑
1.python 字符串通常有单引号('...')、双引号(...)、三引号(...)或('''...''')包围,三引号包含的字符串可由多行组成,一般可表示大段的叙述性字符串。在使用时基本没有差别,

1.python
字符串通常有单引号('...')、双引号("...")、三引号("""... ......

Python 使用C代码——swig

Ref : http://www.swig.org/translations/chinese/tutorial.html
假设你有一些c你想再加Python.。举例来说有这么一个文件example.c
 /* File : example.c */
 #include <time.h>
 double My_variable = 3.0;
 int fact(int n) {
     if (n <= 1) return 1;
&nbs ......

python字典排序

python字典排序
1、 
准备知识:
在python里,字典dictionary是内置的数据类型,是个无序的存储结构,每一元素是key-value对:
如:dict = {‘username’:‘password’,‘database’:‘master’},其中‘username’和& ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号