把美國州名String轉換成2大寫字母列表

# input
input_str = 'ak,ar,az,ca,ma'

# 可以先轉換成大寫字母,然後split by ','
output = input_str.upper().split(',')

# output
print(output)
['AK', 'AR', 'AZ', 'CA', 'MA']

Reference

Python String upper()

Leave a Comment

Your email address will not be published.