![](/img/trans.png)
[英]Printing the content of URLs in a text file, from a text file which contains a list of URLs in python
[英]Python: Formatting a list (which contains a list) for printing
我正在開發一個項目,將輸入轉換為Pig Latin(是的,我確定你以前從未見過這個 ......)並且無法格式化我的輸出。
(對於以下,句子=一個包含用戶輸入(短語)的列表,由phrase.split()分割)
sentence.remove(split)
final = map(str,sentence)
print "Final is (before formatting:", final
final = [sentence[0].capitalize()] , sentence[1:]
#finalFormat = ' '.join(final)
print "Final is", str(final).strip('[]')
#print "FinalFormat is", finalFormat
print "In Pig Latin, you said \"", ' '.join(map(str, final)), "\". Oink oink!"
我得到的是:“在Pig Latin中,你說”['Firstword'] ['secondword','thirdword']“
我正在尋找的是:“在Pig Latin中,你說過”Firstword secondword thirdword“。
基於我的調試打印語句,看起來我的問題仍在線上(從底部開始):
final = [sentence[0].capitalize()] , sentence[1:]
提前致謝!
改變這一行:
final = sentence[0].capitalize() , sentence[1:]
對此:
final = [sentence[0].capitalize()] + sentence[1:]
您將字符串和列表的元組映射到字符串,而不是列表。
注意:在這里使用'single"'
引號將避免"this\\""
丑陋。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.