我想将包含数组中的单词的所有字符串转换为整数.
清单是:
['Met', 'Mod', 'Goa', 'Con', 'Bac', 'Bac', 'Bac', 'Mod', 'Mod', 'Bac',
'Bac', 'Bac', 'Bac', 'Bac', 'Goa', 'Mod', 'Bac', 'Bac', 'Goa', 'Mod',
'Mod', 'Mod', 'Mod', 'Bac']
Run Code Online (Sandbox Code Playgroud)
我想分配Met给1,Mod给2,Goal给3,Con给4,并Bac给5.
如何将列表设为:
['1', '2', '3', '4', '5', '5', '5', '2', '2', '5', '5', '5', '5', '5',
'3', '2', '5', '5', '3', '2', '2', '2', '2', '5']
Run Code Online (Sandbox Code Playgroud) 下面是我的函数代码,用于搜索名为pair的元组列表.列表中的每个元组由两个元素组成.
函数中给出的元素(称为item)可以位于元组的0或1位置,但列表中的所有元组仅由2个元素组成.
pairs = [('a','b'),('c','d'),('e','f'),('c','a')]
def connections(pairs, item):
output = ''
for j in pairs:
if item in j:
output = output + str(j)
return (output)
Run Code Online (Sandbox Code Playgroud)
现在,这段代码将拉出包含其中项目的整个元组.
我想更改此代码只返回元组中的其他元素,并将其作为字符串而不是元组返回.
我有以下代码:
def test_counter(self):
try:
if self.driver.find_element_by_id(self.counter).text == 'texttexttext':
return True
except NoSuchElementException and StaleElementReferenceException:
self.fix_error()
return False
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚为什么NoSuchElementException或者StaleElementReferenceException没有被抓住.
我在一个简单的表达式中遇到了问题,如下所示.
number=int(input("enter the number"))
for n in range(40-101):
if n % number is 0:
print(n)
Run Code Online (Sandbox Code Playgroud)
当我输入10作为输入时,它不输出任何内容作为输出.通过我的小学数学,我可以轻松地假设这应该打印所有可以除以10的数字.
所以问题应该在if声明中.它没有进入print(n).
我正在使用PyCharm Community Edition和Python 3.4
我正在使用Golang编写Web应用程序,我使用的是beego框架.似乎框架具有为golang Web服务器返回的内部状态代码.
我想知道golang或beego中是否有任何方法,或其他工具可以让我控制返回浏览器的状态代码,比如说200或500或其他数字.
我正在openstreetmap上做一个项目,因此为了实现路由机制,我试图实现osrm引用1,但是当我试用时mkdir -p build; cd build; cmake ..,我得到一个错误说:
"CMake错误:源目录"/ home/user1"似乎不包含CMakeLists.txt".
我该怎么做才能解决这个问题!
我想加入此列表:
list1 = [1, 2, 3]
list2 = ['a', 'b', 'c']
merged = ['1a', '2b', '3c']
Run Code Online (Sandbox Code Playgroud)
大小list1和list2总是一样的.
我提取一个数据集行:
(u"[('x-xss-protection', '1; mode=block'), ('x-powered-by', 'PHP/5.4.21 ZendServer/6.2.0'), ('transfer-encoding', 'chunked'), ('expires', '0'), ('vary', 'Accept-Encoding'), ('server', 'nginx'), ('last-modified', 'Thu, 03 Dec 2015 10:20:02 GMT'), ('connection', 'keep-alive'), ('pragma', 'no-cache'), ('cache-control', 'must-revalidate, post-check=0, pre-check=0, public'), ('date', 'Thu, 03 Dec 2015 10:20:02 GMT'), ('x-cached', 'EXPIRED'), ('content-type', 'text/html')]",)
Run Code Online (Sandbox Code Playgroud)
我想找到'内容类型'.我尝试过dict,list,enumerate,str,......但是没有任何作用:(
假设我要打印它的字符串:192.168.1.1
那么我需要的输出是:1.1.168.192
我使用这个命令,但它没有帮助我:
str = array[]
str1 = str[::-1]
print(str1)
Run Code Online (Sandbox Code Playgroud)
输出是:1.1.861.291
所以我不想这样.