1. 程式人生 > >python語法記錄:xrange&range keys()&values() argsort()

python語法記錄:xrange&range keys()&values() argsort()

1.xrange&range 

https://blog.csdn.net/wangyajie_11/article/details/68060133

2.keys()&values()

#
spam = {'color': 'red', 'age': 42}
for v in spam.keys():
    print(v)

color
age
#
spam = {'color': 'red', 'age': 42}
for v in spam:
    print(v)

color
age
#
spam = {'color': 'red', 'age': 42}
for v in spam.values():
    print(v)

red
42

3. argsort()

#
from numpy import*
x=[1,4,3,-1,6,9]
argsort(x)

array([3, 0, 2, 1, 4, 5], dtype=int64)

#
from numpy import*
x=[1,4,3,-1,6,9]
b=argsort(x)
print(b)
print(b[:-6:-2])
print(b[:-6:-1])
print(b[:-7:-1])

[3 0 2 1 4 5]
[5 1 0]
[5 4 1 2 0]
[5 4 1 2 0 3]