简体   繁体   English

将输入中的每个数字设置为其自己的变量

[英]Set each number from input to its own variable

How can I set each number from input to its own variable?如何将输入中的每个数字设置为其自己的变量?

code:代码:

import sys

for line in sys.stdin:

    print(line)

input:输入:

(25,6) (25,10)

I want我想

x1=25 
y1=6
x2= 25 
y2 =10

You can use a regular expression to extract the numbers from the input.您可以使用正则表达式从输入中提取数字。

for line in sys.stdin:
    match = re.search(r'\((\d+),(\d+)\)\s*\((\d+),(\d+)\)', line)
    if match:
        x1, y1, x2, y2 = map(int, match.groups())

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 解压缩字典列表并将每个字典设置为自己的变量 - Unpack a list of dictionaries and set each to its own variable 我应该如何将每个工作表分配给它自己的变量? - How should I assign each worksheet to its own variable? 将每个单独的列设置为具有自己的数据类型 - Set each individual column to have its own datatype 在python中设置可变数量的输入节点 - set variable number of input nodes in python neat 如何在Python 2.7.2中获取一串数字并使每个数字成为列表中自己的元素? - How do I take a string of numbers in Python 2.7.2 and make each number its own element in a list? 这是一个问题。我已经解决了 output 的一半应该是 12345 每个数字在它自己的行 - Here is the question that .i have solve half the output should be 12345 each number on its own line 在多行上输出,我需要将每一行分配给它自己的变量 - Outputting on multiple lines and I need each line to be assigned to its own variable 使用 openpyxl 在特定列中查找一个值并将该行的每个值分配给它自己的变量 - Using openpyxl to find a value in a particular column and assign each value of the row to its own variable 我确实希望每个多处理池工作者都有自己的全局变量副本并能够修改它 - I do want each multiprocessing pool worker to have its own copy of the global variable and be able to modify it 每个子类都包含自己的列表吗? - Have each subclass contain a list of its own?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM