struct
in C, and list
in R d0 = {'wang':3000,'li':4000,'yang':5000}
d0
d2 = [('wang',3000),('li',4000),('yang',5000)]
dict(d2)
d = dict((('wang',3000),('li',4000),('yang',5000)))
d
d1 = {}.fromkeys(('wang','li','yang'),3000)
sorted(d1)
d3 = dict(wang=3000,li=4000,yang=5000)
d3
names = ['wang','li','yang']
salaries = [3000,4000,5000]
d4 = dict(zip(names,salaries))
d4
data = [('SUFE','Shanghai University of Finance and Economics','8000'),
('MSU','Michigan State University','30000'),
('NWU','Northwestern University','9000')]
tmp1 = []
tmp2 = []
for i in range(3):
tmp1.append(data[i][0])
tmp2.append(data[i][2])
d5 = dict(zip(tmp1,tmp2))
d5
for k,v in d4.items():
d4[k] += 1000
d4
d4.keys()
d4.values()
d4.items()
d5 = {'wang':6000,'niu':4000,'liu':7000}
d5.update(d4)
d5
d5.get('wang')
d6 = d5
d5['wang']=10000
d6
d5 = {}
d6
d6 = d5
d5.clear()
d6
import json
js1 = json.dumps(d4)
js1
js2 = json.loads(js1)
js2
import requests
kw = {'q':'Python dict'}
# http://cn.bing.com/search
# http://cn.bing.com/search/?q=%us
r = requests.get('http://cn.bing.com/search',params = kw)
r.url
#print(r.text)
def dct(args1,*argst,**argsd):
print(args1)
print(argst)
print(argsd)
dct('hello','wang','niu','liu','li','yang',a1=1,a2=2,a3=3,a4=5)
class Test:
def kws(self,a,b,*non_keyword,**keyword):
print('a is ',a)
print('b is ',b)
print('non_keyword',non_keyword)
for key in keyword:
print("'%s':%s" % (key,str(keyword[key])))
test = Test()
#dis = test.kws('a','b',('c','d'),e='e',f='f')
dis = test.kws('a','b','c','d',e='e',f='f')
dd = {'wang': 4000, 'niu': 4000, 'liu': 7000, 'li': 5000, 'yang': 6000}
set1 = []
for key in dd.keys():
set1.append(key)
set1.append('wang')
set(set1)
set2 = set('SUFE')
set3 = frozenset('SUFE')
type(set3)
'A' in set2
set2 == set3
set2 < set3
set('SU') < set2
set4 = set('ECNU')
set4 ^ set2
set4 & set2
set4 | set2
set5 = set('ECNU')
set5 -= set2
set5