- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想编写一个函数,它将接受一个字符串并将单词转换为 Pyg 拉丁语。这意味着:
我找到了一个程序,可以将它翻译成 CLOSE 到它必须的样子,但我不确定如何编辑它,以便它可以返回我正在寻找的结果。
def pyg_latin(fir_str):
pyg = 'ay'
pyg_input = fir_str
if len(pyg_input) > 0 and pyg_input.isalpha():
lwr_input = pyg_input.lower()
lst = lwr_input.split()
latin = []
for item in lst:
frst = item[0]
if frst in 'aeiou':
item = item + pyg
else:
item = item[1:] + frst + pyg
latin.append(item)
return ' '.join(latin)
所以,这是我的代码的结果:
pyg_latin('fish')
#it returns
'ishfay'
我希望它返回的内容没有太大区别,但我不知道如何添加它
pyg_latin('fish')
#it returns
'ish-fay'
最佳答案
想想字符串应该是什么样子。
文本 block ,后跟一个连字符,然后是第一个字母(如果它不是元音字母),然后是“ay”。
您可以使用 python 字符串格式或只是将字符串加在一起:
Item[1:] + “-“ + frst + pyg
还值得学习数组切片的工作原理以及字符串如何成为可以通过表示法访问的数组。以下代码似乎适用于您的测试用例。您应该重构它并了解每一行的作用。使解决方案更健壮,但添加测试场景,如“1st”或带标点符号的句子。您还可以构建一个函数来创建 pig 拉丁字符串并返回它,然后重构代码以利用它。
def pg(w):
w = w.lower()
string = ''
if w[0] not in 'aeiou':
if w[1] not in 'aeiou':
string = w[2:] + "-" + w[:2] + "ay"
return string
else:
string = w[1:] + "-" + w[0] + "ay"
return string
else:
string = w + "-" + "way"
return string
words = ['fish', 'frish', 'ish', 'tis but a scratch']
for word in words:
# Type check the incoming object and raise an error if it is not a list or string
# This allows handling both 'fish' and 'tis but a scratch' but not 5.
if isinstance(word, str):
new_phrase = ''
if ' ' in word:
for w in word.split(' '):
new_phrase += (pg(w)) + ' '
else:
new_phrase = pg(word)
print(new_phrase)
# Raise a Type exception if the object being processed is not a string
else:
raise TypeError
关于python - 需要帮助将字符串翻译成 pyg latin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58646822/
Google Web字体上的某些字体支持多个“字符集”。关键是,如果我使用的Web字体仅提供“拉丁”字形,那么将页面翻译成不支持该字形的语言的用户将清楚地注意到困惑的文本。 我希望我的网络字体能够支持
我有(我相信)一个独特的情况;有点困惑。这是交易。 情况:我有一个单一语言的网站,其中所有内容(内容、链接)都使用非拉丁字符。 (西里尔文)(utf-8) 该网站旨在将全局读/说俄语的人联系起来。 问
我在数据库中有 10 个表。其中 9 个只存储 Latin-1 支持的标准 ascii 1 字节字符的数据。其中 1 个要求我存储仅受 UTF8 支持的特殊字符。我想使用相同的 MySQL 连接对象(
我想在 Windows 中从 eclipse 执行 Pig 脚本。我已关注this link 。但它不起作用。是否需要任何插件才能做到这一点?或者只有 pig.jar 就可以了? 最佳答案 试试这个,
题目地址:https://leetcode.com/problems/goat-latin/description/ 题目描述 Asentence S is given, composed of
我正在开发一个将普通单词转换为 pig 拉丁语的函数,但我无法将所有内容组合在一起;它必须适用于加州、手套和八。什么地方不正常? function translate(word) {
我正在尝试编写一个 pig 拉丁语翻译器,但我的网页一直显示未定义,并且无法从文本区域读取。 html 看起来不错,但最终用户需要输入的文本区域中的文本未正确显示。我尝试使用 .textContent
我写这封信是因为今天我遇到了一个问题,尽管到处搜索并尝试了许多不同的语句,但我无法以任何方式解决。 我有这个输入文件: 3 {(car pen house glass)} 5 {(battery ph
我有一个以前用 Latin-1 编码的文件。现在,当我打开这个文件时,我只得到原始编码。即状态行中的 -t:。文件中可能有一些非 Latin-1 字符,至少可以打开其他 Latin-1 文件。 我只想
我正在编写一个程序,它接受一个字符串,将其拆分为单词,将单词转换为 pig 拉丁语,然后返回结果字符串。我已经让它工作到一定程度了。 例如,如果我在程序中输入这些不以元音开头的单词,我会得到: pig
#include #include #include #define isvowel(v) (v=='a' || v=='e' || v=='i' || v=='o' || v=='u') in
所以我是编码的新手,我遇到了一些问题...我的程序应该要求用户输入,并且需要假设所有输入都是小写...并且需要假设没有额外的空格,并且需要假设它以句点结尾。然后该程序会将文本翻译成 pig latin
希望您一切顺利。 我对 Java 和这个网站都很陌生。虽然这可能看起来很长,但我只需要两件事的帮助,所以请帮忙,就像我说的,我对这一切都很陌生,所以越彻底越好。我必须做一个项目,我们必须将常规英语单词
我刚刚收到一个 SQL 插入脚本,但它在重复键输入时失败了: 我正在尝试插入: 1)蒙大拿 2)蒙大拿 我的表都是utf8_spanish2_ci, 谁能解释为什么会这样? 最佳答案 utf8_spa
我想编写一个函数,它将接受一个字符串并将单词转换为 Pyg 拉丁语。这意味着: 如果单词以元音开头,则在末尾添加“-way”。示例:“ant”变成“ant-way”。 如果单词以辅音簇开头,则将该辅音
所以我应该使用 stringConvertToPigLatin(string word) 函数将英语单词转换为 Pig Latin。我在网上能找到的所有答案都是使用 char[],我不允许这样做。如果
这看起来像是家庭作业,但请放心,这不是家庭作业。只是我们在 c++ 类(class)中使用的书中的一个练习,我正在尝试提前阅读指针。 书上的练习告诉我将一个句子拆分成标记,然后将它们中的每一个转换成
所以,我尝试并尝试制作这个 c++ pig 拉丁语程序,但它就是行不通。这是我的代码: int main() { string tmp = ""; char a; cout << "String: "
我最近在工作中遇到了这个问题,是关于pig flatten的。我用一个简单的例子来表达它 两个文件 ===文件1=== 1_a 2_b 4_d ===file2(制表符分隔)=== 1个 2乙 3c
在 Pig 中执行多级过滤后,我得到以下结果 - (2343433,Argentina,2015,Sci-Fi) (2343433,France,2015,Sci-Fi) (2343433,Germa
我是一名优秀的程序员,十分优秀!