美文网首页
NLP学习笔记之基础技能

NLP学习笔记之基础技能

作者: 半笔闪 | 来源:发表于2019-01-02 16:18 被阅读0次

一、字符串操作

1、去空格及特殊符号


s = ' hello, world!'

print(s.strip())                    #hello, world!

print(s.lstrip(' hello, '))        #world!

print(s.rstrip('!'))                # hello, world

2、连接字符串


s1 = 'hello'

s2 = 'world'

s = s1 + s2

print(s)                          #helloworld

3、查找字符串


s1 = 'hello'

s2  = 'e'

print(s1.index(s2))          #1

4、比较字符串


###如使用python2,可直接使用cmp()函数

import operator

s1 = 'hello'

s2 = 'hell'

#相当于a == b

print(operator.eq(s1,s2))       #False

#相当于a < b

print(operator.lt(s1,s2))         #False

#相当于a <= b

print(operator.le(s1,s2))         #False

#相当于a > b

print(operator.gt(s1,s2))         #True

#相当于a >= b

print(operator.ge(s1,s2))         #True

#相当于a != b

print(operator.ne(s1,s2))         #True

5、字符串中的大小写转换


s1 = 'Hello'

print(s1.upper())                      #HELLO

print(s1.lower())                      #hello

6、翻转字符串


s1 = 'hello'

print(s1[::-1])                        #olleh

7、查找字符串


s1 = 'hello'

s2 = 'el'

print(s1.find(s2))                 #1

8、分割字符串


s1 = 'I, want, to, say, hello, world'

s2 = ','

print(s1.split(s2))                           #['I', ' want', ' to', ' say', ' hello', ' world']

9、计算字符串中出现频次最多的字母


import re

from collections import Counter

def get_max_frequency_char(text):

    text = text.lower()

    result = re.findall('[a-zA-Z]',text)

    count = Counter(result)

    m = max(count.values())

    return sorted([x for (x, y) in count.items() if y == m])[0]

二、正则表达式

相关文章

  • NLP学习笔记之基础技能

    一、字符串操作 1、去空格及特殊符号 2、连接字符串 3、查找字符串 4、比较字符串 5、字符串中的大小写转换 6...

  • NLP学习HW1

    NLP入门组队学习 题目理解 报名了NLP组队学习,这是第一天的学习。 赛题名称: 零基础入门NLP之新闻文本分类...

  • HTML5学习笔记之基础标签

    HTML5学习笔记之基础标签 其他HTML5相关文章 HTML5学习笔记之HTML5基本介绍 HTML5学习笔记之...

  • 前提假设感悟

    【学习的内容】 1、听NLP心理实操技能线上课——资源人生的第16课NLP前提假设(上)第15 NLP前提假设(下...

  • 接口测试基础学习笔记

    慕课网接口测试基础视频课学习笔记 接口测试基础之入门篇

  • JavaScript ☞ day1

    JavaScript基础学习笔记之JavaScript基础 HTML中添加JS代码、注释方法、输出方式 docum...

  • 算法/NLP/深度学习/机器学习面试笔记

    算法/NLP/深度学习/机器学习面试笔记 GitHub 地址:https://github.com/imhuay/...

  • NLP自然语言处理-第一章NLP基础

    第一章NLP基础 在本章你将学到NLP(自然语言处理)相关的基础知识。 本章要点包括: NLP基础概念 NLP的发...

  • HTML5基本介绍

    HTML5基本介绍 其他HTML5相关文章 HTML5学习笔记之HTML5基本介绍 HTML5学习笔记之基础标签 ...

  • 春风化雨 润物无声

    《NLP语言魔方》读书笔记 有幸参加单位组织的幸福辅导员的学习,学习的教材是袁立君先生所著的《NLP语...

网友评论

      本文标题:NLP学习笔记之基础技能

      本文链接:https://www.haomeiwen.com/subject/argzlqtx.html