【问题标题】:How to create a sequence of variables and store them in lists while a given condition is not met?如何在不满足给定条件的情况下创建一系列变量并将它们存储在列表中?
【发布时间】:2021-11-21 06:12:33
【问题描述】:

我正在尝试制作一个读取并执行以下条件的程序,我该怎么做?

while condition not met: 

a1,b1,c1 = map(str, input().split())

a2,b2,c2 = map(str, input().split())

a3,b3,c3 = map(str, input().split())
...

...

...
a1, a2, a3 stored in list1[]

b1, b2, b3 stored in list2[]

c1, c2, c3 stored in list3[]

【问题讨论】:

  • 请解释您的问题与您使用的标签[python-requests]有何关系?
  • 添加您尝试过但没有奏效的内容:我在这里看不到任何问题。顺便说一句,map(str, input().split() 的作用也不过是input().split()。你想更普遍地做什么?这和python-requests有什么关系?
  • 我不太准确:map(str, input.split() 确实做了一些事情——它浪费了 cpu 周期将 strs 转换为 strs。但是 input.split() 的输出已经是一个字符串列表
  • input 正在返回字符串,因此无需再次转换:map(str, input().split()) -> input().split() `
  • a3,b2,c3 : 这应该是 a3, b3,c3 吗?

标签: python python-3.x list while-loop


【解决方案1】:

不好的方法

list = [][]
while condition not met:
a, b, c = map(str, input().split())
list[0].append(a)
list[1].append(b)
list[2].append(c)

a1, a2, a3 ... 将存储在list[0]

b1, b2, b3 ... 将存储在list[1]

c1, c2, c3 ... 将存储在list[2]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-24
    • 2021-09-01
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-16
    • 2011-04-07
    相关资源
    最近更新 更多