//sixth day to study python(2016/8/7)

32. In python , there are have an special type dictionary , it is same with oc.

such as:

dicOne = {'wyg':'write code change world', 'roy':'you cand do it', 'tom':'just do it'}

dicOne

->

{'wyg':'write code change world', 'roy':'you cand do it', 'tom':'just do it'}

dicOne['wyg']

->

'wirte code change world'

dicOne['wyg'] = 'believe youself'

dicOne

->

{'wyg':'believe youself', 'roy':'you cand do it', 'tom':'just do it'}

dicTwo = dict(wyg = 'just do it', roy = 'you can do it')

dicTwo

->

{'wyg':'just do it', 'roy':'you can do it'}

dicThree = dict((('r':'rrr'),('t':'ttt')))

dicThree

->

{'r':'rrr','t':'ttt'}

33. In python ,dictionary type we can use everywhere, so we should learn it more deeply.

fromkeys()

dict1 = {}

dict1.fromkeys((1, 2, 3))

->

{1:None, 2:None, 3:None}

dict1.fromkeys((1,2,3),'Number')

->

{1:'Number', 2:'Number', 3:'Number'}

dict1.fromkeys((1,2,3),('one','two','three'))

->

{1: ('one', 'two', 'three'), 2: ('one', 'two', 'three'), 3: ('one', 'two', 'three')}

keys()

dict1 = dict.fromkey(range(5),'roy')

dict1

->

{0:'roy',1:'roy',2:'roy',3:'roy',4:'roy'}

for eachKey in dict1.keys():

print(eachKey)

->

0

1

2

3

4

5

values()

for eachValue dict1.values():

print(eachValue)

->

roy

roy

roy

roy

roy

items()

for eachItem in dict1.items():

print(eachItem)

->

(0, 'roy')
      (1, 'roy')
      (2, 'roy')
      (3, 'roy')
      (4, 'roy')

get()
      dict1.get(0)

->

'roy'

print(dict1.get(100))

->

None

dict1.get(1,'no keyvalue')

->

'roy'

dict1.get(100,'no keyvalue')

->

'no keyvalue'

in , not in (key)

3 in dict1

True

100 in dict1

False

clear()

dict1.clear()

->

{}
      copy() (light copy)

a = {1:'one',2:'two'}

b = a.copy()

c = a

id(a)    id(b)   id(c)

->

4346314824     4386886856     4346314824

c[3] = 'three'

a

->

{1:'one',2:'two',3:'three'}

b

->

{1:'one',2:'two'}

c

->

{1:'one',2:'two',3:'three'}

pop()
    a.pop(2)

->

{1:'one',2:'three'}

popitem()

a.popitem()

-> rand pop an object

setdefault()

a = {1:'one'}

a.setdefault(2)

a

->

{1:'one',2:None}

a.setdefault(3,'three')

{1:'one',2:None,3:'three}

update()
    b = {'roy':'wyg'}

a.update(b)

->

{1:'one',2:None,3:'three,'roy':'wyg'}

34. we have learned dictionary ,now we learn set continue.

num = {}

type(num)

<class 'dict' at 0x100229b60>

num = {1,2,3}

type(num)

<class 'set' at 0x10022e420>

in set ,all value is only but no support index. such as:

num2 = {1,2,3,4,5,5,6}

num2

->

{1,2,3,4,5,6}

num3 = set([1,2,3,4])

num3

->

{1,2,3,4}

now how can remove repeat value from list

such as:

a = [1,2,3,4,5,5,6]

b = []

for each in a:

if each not in b:

b.append(each)

b

->

[1,2,3,4,5,6]

now that we have learned set ,how to achieve it by set

a = list(set(a))

->

[1,2,3,4,5,6]

Python Base Three的更多相关文章

  1. Python Base of Scientific Stack(Python基础之科学栈)

    Python Base of Scientific Stack(Python基础之科学栈) 1. Python的科学栈(Scientific Stack) NumPy NumPy提供度多维数组对象,以 ...

  2. Python Base Four

    35. In python, file operation syntax is similar to c. open(file,'r',……) //the first parameters is ne ...

  3. Python Base One

    //this is my first day to study python, in order to review, every day i will make notes (2016/7/31) ...

  4. Python Base Five

    // 8 day(2016/8/11) 38. In python , it is oop. class Baskball:         def setName(self, name):      ...

  5. Python Base Two

    //fourth day to study python 24. In python , how to create funcation. we can use def to define funca ...

  6. 2019-04-18 Python Base 1

    C:\Users\Jeffery1u>python Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64 ...

  7. python base 64

    python中base64编码与解码   引言: 在一些项目中,接口的报文是通过base64加密传输的,所以在进行接口自动化时,需要对所传的参数进行base64编码,对拿到的响应报文进行解码: Bas ...

  8. Python Base HTTP Server

    import BaseHTTPServer import cgi, random, sys MESSAGES = [ "That's as maybe, it's still a frog. ...

  9. 基于Python+协程+多进程的通用弱密码扫描器

    听说不想扯淡的程序猿,不是一只好猿.所以今天来扯扯淡,不贴代码,只讲设计思想. 0x00 起 - 初始设计 我们的目标是设计一枚通用的弱密码扫描器,基本功能是针对不同类型的弱密码,可方便的扩展,比如添 ...

随机推荐

  1. 使用EventLog组件向本机现有日志中添加条目

    实现效果: 知识运用: EventLog组件的MachineName属性 //获取或设置在其上读取或写入事件的计算机名称 public string MachineName  {get;set; } ...

  2. SQL Server将列以分隔符分割后存到临时表

    begin if object_id('tempdb..#t') is not null drop table #t; create table #t ( filepath ) ); declare ...

  3. Form组件的验证流程及扩展(钩子)

    Form组件的验证流程及扩展(钩子) 常用的form class TestForm(Form): t1 = fields.CharField( widget=widgets.Textarea # 输入 ...

  4. Python基础篇 -- 集合

    set集合 set 中的元素是不重复的,无序的 里面的元素必须是可hash的,(int str tuple bool) set 就是dict 类型的数据,但是不保存value 只保存 key set集 ...

  5. 01_4_Struts路径问题

    01_4_Struts路径问题 1. Struts路径问题说明 struts2中的路径问题是根据action的路径而不是jsp路径来确定,所有尽量不要使用相对路径. 虽然可以使用redirect方式解 ...

  6. 解决Windows 与Mac 双系统下的蓝牙设备共用的问题

    不知道有多少人和我一样用的蓝牙鼠标或者键盘,有的话应该都会遇到同一个问题:即在一个系统下配好对后在另一个系统必须重新配对才能使用,很是麻烦.还要将蓝牙设备进入发现模式,OS下搜索,连接....终于昨天 ...

  7. kali下安装中文输入法

    参考网址:https://blog.csdn.net/qq_37367124/article/details/79229739 更性源 vim /etc/apt/source.list 设置更新源 更 ...

  8. 如何使用 HTML5 的picture元素处理响应式图片

    来自: http://www.w3cplus.com/html5/quick-tip-how-to-use-html5-picture-for-responsive-images.html 图片在响应 ...

  9. 逃离迷宫 HDU - 1728(bfs)

    逃离迷宫 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  10. UVa 1354 枚举子集 Mobile Computing

    只要枚举左右两个子天平砝码的集合,我们就能算出左右两个悬挂点到根悬挂点的距离. 但是题中要求找尽量宽的天平但是不能超过房间的宽度,想不到要怎样记录结果. 参考别人代码,用了一个结构体的vector,保 ...