如何在python中计算输入行数
我想打印出哪一行包含某些字母 例如,如果0是某个字母, 当输入像如何在python中计算输入行数,python,list,row,Python,List,Row,我想打印出哪一行包含某些字母 例如,如果0是某个字母, 当输入像 1111132323132323232313232 1323232313132323132323232 1232323201231323232313232 多行输入 我期望的输出是3。(因为第三行包含“0”) 我怎样才能把第四行打印出来?我希望它能工作 a=[1111132323132323232313232,1323232313132323132323232,1232323201231323232313232] for i i
1111132323132323232313232
1323232313132323132323232
1232323201231323232313232
多行输入
我期望的输出是3。(因为第三行包含“0”)
我怎样才能把第四行打印出来?我希望它能工作
a=[1111132323132323232313232,1323232313132323132323232,1232323201231323232313232]
for i in range(len(a)):
if your_number in list(str(a[i])):
print(i+1) # if you want 0 to n than i otherwise i+1
只需将此概念用于任何维度数组,首先将其转换为列表并签入该列表。您需要使用字符串和
运算符来查找字符串中的特定字符
或
你也可以使用
例如:
ip='''1111132323132323232313232 1323232313132323132323232 1232323201231323232313232'''
a=ip.split().index([x for x in ip.split() if '0' in x][0])
print (a+1)
或带过滤器的
:
ip = '''1111132323132323232313232
1323232313132323132323232
1232323201231323232313232'''
strList=ip.split()
result = filter(lambda x: '0' in x ,strList)[0]
print(strList.index(result)+1)
您有一维数组还是二维数组?请澄清输入的格式。