//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. Jquery库插件大全(工作中遇到总结)

    Jquery UI所有插件下载:http://jqueryui.com/download/all/ Jquery layer灯箱等演示与帮助:http://sentsin.com/jquery/lay ...

  2. MySQL-08 MySQL8.0新特性

    性能 MySQL 8.0 在一定的用户访问条件下,速度要比 MySQL 5.7 快 2 倍.MySQL 8.0 在以下方面带来了更好的性能:读/写工作负载.IO 密集型工作负载.以及高竞争(" ...

  3. 利用Python的pyHook包来进行键盘监听

    最近在实习的时候发现一件很蛋疼的事情,那就是我们组的项目因为有后台进程,所有每次运行完以后后台进程都必须要自己手动关闭,每次编译之前忘记关就会有一大堆编译错误,我就想直接弄个可以快捷键直接关闭算了   ...

  4. Mybatis学习记录(3)

    1.输出映射和输入映射 Mapper.xml映射文件定义了操作数据库的sql,每个sql就是一个statement,映射文件是mybatis的核心. (1)parameterType(输入类型)   ...

  5. 08GNU as汇编

    1. 概述 ​ 由于操作系统许多关键代码要求有很高的执行速度和效率,因此在一个操作系统源代码中通常就会包含大约 10% 左右的起关键作用的汇编语言程序量.Linux 操作系统也不例外,它的 32 位初 ...

  6. [图文] Fedora 28 使用 Virt-Manager 创建 KVM 虚拟机以及 配置 KVM 虚拟机

    实验说明: 往后的许多实验都将以Linux平台下的 KVM虚拟机为主,所以不可少的就是 Virt-Manager 虚拟机管理器. 本章将对如何安装和使用Virt-Manager管理器进行讲解,并且会对 ...

  7. EditPlus 比较完整的快捷键记录

    FileFtpUpload Ctrl+Shift+S 上传文件到FTP 服务器 FileNew Ctrl+N 新建普通的文本文档 FileNewHtml Ctrl+Shift+N 创建一个空白的 HT ...

  8. python中的内建函数

    本文用作记录python中的内建函数及其功能,本文内容随时补充. 完整的内建函数及其说明参考官方文档:    https://docs.python.org/3.5/library/functions ...

  9. 蓝牙nrf52832的架构和开发(转载)

    相比TI的CC254X.DIALOG的DA1458X,nordic推出的nrf51822和nrf52832在架构和开发商都有自己独特的地方.这几颗产品都是蓝牙低功耗芯片.DA1458X使用OTP硬件架 ...

  10. gdb调试时查看内存

    x/<n/f/u> <addr> n.f.u是可选的参数,<addr>表示一个内存地址 1) n 是一个正整数,表示显示内存的长度,也就是说从当前地址向后显示几个地 ...