题解 | #坐标移动# 空值处理
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
'''从(0,0)点开始移动:
A表示向左移动
D表示向右移动
W表示向上移动
S表示向下移动
'''
while 1:
try:
s=input().split(';')
#须先删掉空字符串 s.remove('') 只能删掉第一个'',后面的''导致函数停止
s = list(filter(None, s))
#filter()可以过滤掉空值,将结果重新组成列表即可
#print(s)
x,y=0,0
for i in s:
if i[0] in 'ADWS' and i[1:].isdigit():
dir,step=i[0],int(i[1:])
#print(dir,step)
if i[0]=='A':
x -= step
elif i[0]=='D':
x += step
elif i[0]=='W':
y += step
elif i[0]=='S':
y -= step
#print(x,',',y)
print(str(x)+','+str(y))
except: # 遇到空白/空格/空行自动停止
break
'''
d={1:'fsdf',2:'sdfds'}
print(len(d),d.items())
a='4234njn'
b='41434'
print(b.isdigit())
l=['','gf','dgdf','hher','','grg','']
try:
while True:
l.remove("")
except ValueError:
pass
for i in l:
print(i)
'''
删掉空字符串:
s.remove('') 只能删掉第一个'',后面的''导致函数停止
s = list(filter(None, s)) #filter()可以过滤掉空值,将结果重新组成列表即可
