Python Base Three
//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的更多相关文章
- Python Base of Scientific Stack(Python基础之科学栈)
Python Base of Scientific Stack(Python基础之科学栈) 1. Python的科学栈(Scientific Stack) NumPy NumPy提供度多维数组对象,以 ...
- Python Base Four
35. In python, file operation syntax is similar to c. open(file,'r',……) //the first parameters is ne ...
- Python Base One
//this is my first day to study python, in order to review, every day i will make notes (2016/7/31) ...
- Python Base Five
// 8 day(2016/8/11) 38. In python , it is oop. class Baskball: def setName(self, name): ...
- Python Base Two
//fourth day to study python 24. In python , how to create funcation. we can use def to define funca ...
- 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 ...
- python base 64
python中base64编码与解码 引言: 在一些项目中,接口的报文是通过base64加密传输的,所以在进行接口自动化时,需要对所传的参数进行base64编码,对拿到的响应报文进行解码: Bas ...
- Python Base HTTP Server
import BaseHTTPServer import cgi, random, sys MESSAGES = [ "That's as maybe, it's still a frog. ...
- 基于Python+协程+多进程的通用弱密码扫描器
听说不想扯淡的程序猿,不是一只好猿.所以今天来扯扯淡,不贴代码,只讲设计思想. 0x00 起 - 初始设计 我们的目标是设计一枚通用的弱密码扫描器,基本功能是针对不同类型的弱密码,可方便的扩展,比如添 ...
随机推荐
- 在linux命令行下如何访问网址
1. wget Ubuntu系统自带,会将访问的首页下载到本地 admin@iZj6c9c6vaqj1i0a9j7h78Z:~$ wget www.baidu.com --2019-04-20 17: ...
- 组件的通信 :provide / inject 对象进入后,就等于不用props,然后内部对象,直接复制可以接受数组,属性不能直接复制,可以用Object.assgin覆盖对象,或者Vue的set 双向绑定数据
组件的通信 :provide / inject 对象进入后,就等于不用props,然后内部对象,直接复制可以接受数组,属性不能直接复制,可以用Object.assgin覆盖对象,或者Vue的set 双 ...
- ctrl+shift+f
ctrl+f是在当前文件寻找某个参数 ctrl+shift+f是在整个工程目录下寻找某个参数
- 剑指offer64 数据流中的中位数
priority_queue优先级队列,他的模板声明带有三个参数,priority_queue<Type, Container, Functional> Type 为数据类型, Conta ...
- VS Code:设置多行注释快捷键
多行注释,也叫块注释. 如何查看,并修改VS Code中的多行注释快捷键呢? 1). 点击 首选项 - 键盘快捷方式 2). 在搜索框中输入 comment 3). 这个时候可以看到“切换块注释”的信 ...
- kali添加更新源
/etc/apt/sources.list 具体方法参考: http://blog.csdn.net/gmnet/article/details/14471835 http://blog.sina.c ...
- 下载旧版本的JDK
下载旧版本的JDK 有的时候我们需要去下载旧版本的JDK,但是进入Oracle官网,显示的总是新版的JDK,这里告诉大家怎么样去下载旧版本的JDK. 首先去JavaSE的 下载界面 拉到最下面,找到这 ...
- java/jsp执行sql语句的方式
首先给出sql驱动包 引入sql包 import java.sql.*;//java <%@ page import="java.sql.*"%>//jsp 连接mys ...
- CentOS7搭建DNS服务器
DNS是域名系统(Domain Name System)的缩写,它的作用是将主机名解析成IP(正向解析),从IP地址查询其主机名(反向解析). DNS的工作原理(1)客户机发出查询请求当被询问到有关本 ...
- 欧拉函数:HDU1787-GCD Again(欧拉函数的模板)
GCD Again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...