例如:30 2 3 4 31 1 4 32 3 4 5 6 33 2 7 8
其中
30是标签,2是数字个数,3 4为2个数字
31是标签,1是数字个数,4 是1个数字
32是标签,3是数字个数,4 5 6是3个数字
33是标签,2是数字个数,7 8 是两个数字
练习1,当输入标签,打印该标签对应的数字,例如输入32 打印:4、5、6
练习2,当输入标签,计算该标签是列表中第几个标签,例如输入32 打印:3
str1 = '30 2 3 4 31 1 4 32 3 4 5 6 33 2 7 8'
num_list = str1.split()
print(num_list)
num = '32'
i = num_list.index(num)
print(i)
value = num_list[i+2:i+2+int(num_list[i+1])]
print(value)
count = 0
i = 0
while True:
if num_list[i] == num:
count += 1
print(count)
break
else:
count += 1
i = i+1+int(num_list[i+1])+1