请参阅下面的代码片段,我想["metric1", "metric2"]成为 RunTask.process 的输入。但是,它分别使用“metric1”和“metric2”运行了两次
def run():
pipeline_options = PipelineOptions(pipeline_args)
pipeline_options.view_as(SetupOptions).save_main_session = save_main_session
p = beam.Pipeline(options=pipeline_options)
root = p | 'Get source' >> beam.Create([
"source_name" # maybe ["source_name"] makes more sense since my process function takes an array as an input?
])
metric1 = root | "compute1" >> beam.ParDo(RunLongCompute(myarg="1")) #let's say it returns ["metic1"]
metric2 = root | "compute2" >> beam.ParDo(RunLongCompute(myarg="2")) #let's say it returns ["metic2"]
metric3 = (metric1, metric2) | beam.Flatten() | beam.ParDo(RunTask()) # I want ["metric1", "metric2"] …Run Code Online (Sandbox Code Playgroud) text = "Bob|19|01012017"
pat = re.compile("(?P<name>.+)|.*|(?P<bday>.+)") #hopefully this regex is correct
result = pat.match(text)
d = result.groupdict()
print d
Run Code Online (Sandbox Code Playgroud)
我得到的 d 是:
{'bday': None, 'name': 'Bob|19|01012017'}
Run Code Online (Sandbox Code Playgroud)
我想要的是:
{bday: "01012017", name: "Bob"}
Run Code Online (Sandbox Code Playgroud)
有人可以指出我做错了什么吗?我只需要 dict 的两个字段,所以我没有写年龄部分。
我想知道我是否可以在python词典中进行"模糊"的键搜索.例如,我有一个这样的字典:
data = { "Google.com" : value1, "StackOverFlow": value2, ....}
Run Code Online (Sandbox Code Playgroud)
如果我有一个字符串
name= "Google" or name = "google" or even name = "gooogle"
Run Code Online (Sandbox Code Playgroud)
我想在我的字典中访问value1(其键是"Google.com"),我该怎么做?我知道我可以遍历键列表并进行一些字符串处理但是如果我有多个名字,我想做这样模糊的搜索,它会是O(n ^ 2)对吗?有没有有效的方法呢?假设数据字典非常大.
希望我的问题很明确......
我想知道如何将类型A的变量x附加到Option [List [A]].
val opt = Option[List[A]] which is initially None.
Run Code Online (Sandbox Code Playgroud)
现在我如何将x添加到A列表?
是吗:
opt.get ++ x
Run Code Online (Sandbox Code Playgroud)
它是否通过使用get改变了opt值?
希望我的问题很明确