题解 | #参数解析# #简单易懂#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
string = input()
#基本思路是先用"分割,但是我想保留"",所以我把”换成```"
string = string.replace(' "','```"')
string = string.replace('" ','"```')
#用```分割,这样可以保留"
string = string.split('```')
result = []
for i in string:
#如果是正常的中间没有空格而且不是引号
if ' ' not in i and i[0]!='"':
result.append(i)
#如果有引号,那就去掉引号加入我们的result
elif i[0]=='"':
i=i.replace('"','')
result.append(i)
#如果没有引号而且中间有空格,代表需要进一步分割,按空格分割
else:
result.append(i.split())
count = 0
#先数一下这个二维list有多少个东西
for i in result:
if type(i)!=list:
count+=1
else:
for j in i:
count+=1
#打印出来有几个东西
print(count)
#打印出来结果
for i in result:
if type(i)!=list:
print(i)
else:
for j in i:
print(j)


查看5道真题和解析