可能重复:
反向字典查找 - 使用Python 进行字典的Python
反向映射
如何在字典中获取索引的键?
例如:
i = {'a': 0, 'b': 1, 'c': 2}
Run Code Online (Sandbox Code Playgroud)
所以,如果我想获得i [0]的关键,它将返回'a'
数组中的原始数据:
a = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
期望的输出:
['1 2 3', '4 5 6', '7 8 9']
我知道使用该while语句是低效的,所以我需要帮助.X_X
我需要这方面的帮助.如何将字符串转换为变量/对象/实例名称,因为我不知道如何对其进行分类.
假设我的代码是:
a = {}
b = {}
class Test:
def getKeys(self, var):
return var.keys() #where var refers to the dictionary and its a string initially
Run Code Online (Sandbox Code Playgroud) 我需要这个xx的帮助
假设我的php有3个变量
<?php
$var1 = "1";
$var2 = "2";
$var3 = "3";
?>
Run Code Online (Sandbox Code Playgroud)
所以在"exec"部分我有点卡住和困惑,我如何将这3个变量传递到我的python脚本中,我如何在我的python脚本中收到这3个变量?
好吧我如何使用正则表达式删除http AND/OR www只是为了获得http://www.domain.com/到domain.com
假设x为任何类型的TLD或cTLD
输入示例:
www.domain.x
输出:
domain.x
如何在同一个文件中调用类.我的文件是这样的:
class one:
def get(self):
return 1
class two:
def init(self):
get class one get()
Run Code Online (Sandbox Code Playgroud)
如何获得一级get().对不起,我的英语不好.
可能重复:
可以从数组中分配多个变量吗?
如果在python我能做到这一点
x = "Hi there and hello there"
v1, v2, v3, v4, v5 = x.split(" ")
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在JavaScript中做到这一点..
如何从正则表达式中排除空格,但不会忽略特殊字符.我目前的代码是: -
pattern=re.compile("[^\w]")
var = pattern.sub('', var)
Run Code Online (Sandbox Code Playgroud)
我知道\ w会删除所有空格字符,但是如何只排除空格?
例:
var = "hi this is test!@#$%%^^"
Run Code Online (Sandbox Code Playgroud)
在正则表达式之后它将成为:
var = "hi this is test"
Run Code Online (Sandbox Code Playgroud)