list.extend()

list1.extend(list2(or string)) 将list2(or string)的所有元素添加到list1中;

list1.append(list2(or string)) 将list2(or string)作为一个元素添加到list1中;

注意:dtype( list1.extend() ) = Nonetype 所以无法对其进行列表操作(.sort()之类的)  ->append也一样

  1 class Solution:
2 def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
3 nums1.extend(nums2)
4 nums1.sort()
5 x=len(nums1)
6 if (x%2)==1:
7 i=int((x-1)/2)
8 return float(nums1[i])
9 else:
10 i=int(x/2)
11 j=int((x/2)-1)
12 return (nums1[i]+nums1[j])/2.0

median of 2 list

list1(or string1)[i:j:s]

创建新list2:元素为list1的i至j-1,元素间步长为s;

s:default=1,当s<0且i,j缺损,i,j分别默认为-1,-len(list)-1,特例:当s=-1时逆序返回。

 a = str('hello world!')
b = [1,2,3,4,5,6]
print(a[::-1])
print(b[::-1])
!dlrow olleh
[6, 5, 4, 3, 2, 1]

cmp()

cmp( x, y ),如果 x < y 返回 -1, 如果 x == y 返回 0, 如果 x > y 返回 1(x,y为数值表达式)。

if-else;if-elif

str.strip()

str.strip('X')移除首尾的X元素,default:whitespace,tab

inter.join()

inter.join(list(or string)),将inter加入list每个元素之间,并返回处理后的string,类似于spilt的相反。

 a="-*-"
d=['自','己','看','!']
x=a.join(d)
print(x)
type(x)
>>>'自-*-己-*-看-*-!'
>>>str

str.spilt()

str.split('X',nums),对str进行切片nums次,返回一个list,  str.spilt()[-1]为取list中的最后一个元素

str.rspilt()

用法类似str.split(),但是从str的末尾开始

判断list或者string元素是否为空:

为空的str or list bool值为False,或者len(str or list)=0

 str_a  = str('我自己看')
str_b = ('')
list_a = ['我','自','己','看']
list_b = []
print(bool(str_a))
print(bool(str_b))
print(bool(list_a))
print(bool(list_b)) >>>Ture
>>>False
>>>Ture
>>>False

str.replace('ever','now')

将str中的ever用now替代,ever和now可以是字符串或者字符

np.linspace(start, stop, num= , endpoint=True, retstep=False, dtype=None, axis=0,)

返回从start 到stop 均匀分成num个点的数列,endpoint 默认为True时,包含stop,即相邻点间隔为(stop-start)/(num-1);endpoint为False时返回数列不包含stop,相邻点间隔为(stop-start)/num。

np.tile(Arr, (tuple))

将Arr按tuple中的数据展开,注意Arr的维度index变化

list 删除元素的三种方法

函数 代码 说明
del del list[i] ①根据索引删除;②删除索引范围内的元素;③删除整个列表。 del操作没有返回值
pop list.pop(i) 根据索引删除,返回索引位置的元素
remove list.remove(value) 删除第一个符合条件的元素,不是根据索引删除,返回Nonetype

List与numpy.array相互转换

#List转numpy.array:

list_ = np.array(list) 

#numpy.array转List:

arr = list_.tolist() 

leetcode中的python学习的更多相关文章

  1. [Python] 学习资料汇总

    Python是一种面向对象的解释性的计算机程序设计语言,也是一种功能强大且完善的通用型语言,已经有十多年的发展历史,成熟且稳定.Python 具有脚本语言中最丰富和强大的类库,足以支持绝大多数日常应用 ...

  2. 记录Python学习中的几个小问题

    记录Python学习中的几个小问题,和C#\JAVA的习惯都不太一样. 1.Django模板中比较两个值是否相等 错误的做法 <option value="{{group.id}}&q ...

  3. VS2013中Python学习笔记[Django Web的第一个网页]

    前言 前面我简单介绍了Python的Hello World.看到有人问我搞搞Python的Web,一时兴起,就来试试看. 第一篇 VS2013中Python学习笔记[环境搭建] 简单介绍Python环 ...

  4. VS2013中Python学习环境搭建

    VS2013中Python学习笔记[环境搭建] 前言 Python是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. Python的设计具有很强的可读性,相比其他语言经常使用英文关键字, ...

  5. python学习第九讲,python中的数据类型,字符串的使用与介绍

    目录 python学习第九讲,python中的数据类型,字符串的使用与介绍 一丶字符串 1.字符串的定义 2.字符串的常见操作 3.字符串操作 len count index操作 4.判断空白字符,判 ...

  6. python学习第八讲,python中的数据类型,列表,元祖,字典,之字典使用与介绍

    目录 python学习第八讲,python中的数据类型,列表,元祖,字典,之字典使用与介绍.md 一丶字典 1.字典的定义 2.字典的使用. 3.字典的常用方法. python学习第八讲,python ...

  7. python学习第七讲,python中的数据类型,列表,元祖,字典,之元祖使用与介绍

    目录 python学习第七讲,python中的数据类型,列表,元祖,字典,之元祖使用与介绍 一丶元祖 1.元祖简介 2.元祖变量的定义 3.元祖变量的常用操作. 4.元祖的遍历 5.元祖的应用场景 p ...

  8. python学习第六讲,python中的数据类型,列表,元祖,字典,之列表使用与介绍

    目录 python学习第六讲,python中的数据类型,列表,元祖,字典,之列表使用与介绍. 二丶列表,其它语言称为数组 1.列表的定义,以及语法 2.列表的使用,以及常用方法. 3.列表的常用操作 ...

  9. python中confIgparser模块学习

    python中configparser模块学习 ConfigParser模块在python中用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(section ...

随机推荐

  1. Tensorflow实战系列之四:

    这个是第四篇,打算写一些语义分割的内容实战.

  2. NFS 配置文件及在iptables中的配置

    yum 安装nfs即可 ( yum install nfs-utils ) cat /etc/exports /data/nfsdata 10.10.10.194(rw,no_root_squash) ...

  3. CSS3简单画出3d图形

    1.气球 2.泳圈 1.2两图实现代码分别如下: <html> <head> <meta charset="utf-8"> <meta h ...

  4. Spring4中使用通用Mapper

    1.  在Spring4中使用通用Mapper Spring4增加了对泛型注入的支持,这个特性对通用Mapper来说,非常的有用,可以说有了这个特性,可以直接在Service中写Mapper<U ...

  5. C# 温故之.NET 异步

    Bitter Coffee的温故之.NET 异步 相当经典(请允许我用经典两字),读了好几遍,留存.

  6. ./sample_mnist: error while loading shared libraries: libnvinfer.so.4: cannot open shared object file: No such file or directory

    Your library is a dynamic library. You need to tell the operating system where it can locate it at r ...

  7. JS-斜杠和反斜杠的转换

    例子:var url = "http://localhost:64177/Home/AccordionIndex"; 将斜杠转换成反斜杠: url = url .replace(& ...

  8. QT之两种模态对话框的调用

    模态对话框:就是没有关闭它之前,不能再与同一个应用程序的其他窗口进行交互. 1.show调用 LoginDialog *dlg = new LoginDialog(); dlg->setModa ...

  9. Spring学习札记(一)

    写在前面:spring的两大特点:IOC与aop.IOC(Inverse of Control):控制反转,也可以称为依赖倒置.降低耦合.AOP:即面向切面编程. 从Spring的角度看,AOP最大的 ...

  10. 2017年4月28日16:40:40 log

    //TODO order  CreateOrderServiceHandler  generateManagementCustomer 子活动名称和uid