Think before you speak, read before you think.

python raw_input用map转换为 list

raw_input是用来提示输入的

把输入的字符以转化为list

>>> input_words = raw_input(‘input some words: ‘)

input some words: shang hai zi lai shui lai zi hai shang.

>>> input_words

‘shang hai zi lai shui lai zi hai shang.’

使用 map 将数据转换为 list

>>> input_list = map(str, input_words.split())
>>> input_list
[‘shang’, ‘hai’, ‘zi’, ‘lai’, ‘shui’, ‘lai’, ‘zi’, ‘hai’, ‘shang.’]


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *