当前位置: 首页 > 娱乐 > 正文

python3常用单词句子 Python在执行时

作者:admin 发布时间:2024-02-01 02:18:44 分类:娱乐 浏览:58


  1.python需要记住哪几十个单词

  楼上的程序存在诸多问题,如没有处理标点,文件读取方法错误等。

  请问楼主要区分大小写吗?如果区分的话,就按照下面的来: import re def get_word_frequencies(file_name): dic={} txt=open(filename, 'r').read().splitlines() #下面这句替换了除了'-'外的所有标点,因为'-'可能存在于单词中。 txt=re.sub(r'[^u4e00-u94a5wd-]', ' ', txt) #替换单独的'-' txt=re.sub(r' - ', ' ', txt) for line in : for word in line.split(): #如果不区分大小写,那就一律按照小写处理,下面那句改为dic.setdefault(word.lower(), 0) dic.setdefault(word, 0) dic[word] +=1 print dic if __name__='__main__': get_word_frequencies('test.txt') 有问题继续追问吧。

  2.python 提取有关键词的句子怎么做

  高频词提取:

  # !/usr/bin/python3

  # coding:utf-8

  import jieba.analyse

  jieba.load_userdict('dict.txt') # dict.txt自定义词典

  content=open('kw.txt', 'rb').read()

  tags=jieba.analyse.extract_tags(content, topK=10) # topK 为高频词数量

  print("

  ".join(tags))

  3.求问用python实现:编写程序,计算用户输入的英文句子中的词语数

  这个你需要去网上找一个python版本的英文的分词包,做句子的分词,当然最简单的你可以按空格对英文进行分词。。用text.split(" ")来分。然后统计每个词的长度并求平均值

  cc=raw_input('input a string:')

  sen_list=cc.split(" ")

  count=len(sen_list)

  sum=0

  for word in sen_list:

  if word:

  sum +=len(word)

  avg=sum*1.0/count

  print avg

  4.python 对一段英文文本整理

  >> s="D-typed variables, Python; really?!! god's 'its "

  >>> reg=re.compile(r"w+[.,;'"!?-]w+|w+|[.,;'"!?-]")

  >>> reg.findall(s)

  ['D-typed', 'variables', ',', 'Python', ';', 'really', '?', '!', '!', "god's", "'", 'its']

  >>>

  5.用Python任意输入三个英文单词,按字典顺序输出

  words=raw_input("please input three words")print sorted(words.split())例如:a=str(raw_input(u"请输入用空格分开的单词:"))b=a.split()b.sort()for i in b:print i扩展资料:Python在执行时,首先会将.py文件中的源代码编译成Python的byte code(字节码),然后再由Python Virtual Machine(Python虚拟机)来执行这些编译好的byte code。

  这种机制的基本思想跟Java,.NET是一致的。然而,Python Virtual Machine与Java或.NET的Virtual Machine不同的是,Python的Virtual Machine是一种更高级的Virtual Machine。

  参考资料来源:百度百科-Python。

  6.python中如何将一个英文句子中的每个单词的首字母由小写转换为大写

  我简单写了一个,题主看行不行

  def convert_initial(old: str) -> str:

  new=""

  i=0

  while i < len(old):

  if (i==0) or (old[i - 1]==" "):

  new +=old[i].upper()

  else:

  new +=old[i]

  i +=1

  return new运行示例:

  >>> convert_initial("are u ok?")

  'Are U Ok?'

  >>> convert_initial("who am i?")

  'Who Am I?'

  >>> convert_initial("here u r.")

  'Here U R.'

python3常用单词句子 python需要记住哪几十个单词 本文分享到此结束,希望对大家有所帮助。


标签:in单词英文


最新推荐

关灯