How to transform string of space-separated key,value pairs of unique words into a dict

前端 未结 9 975
走了就别回头了
走了就别回头了 2020-11-30 14:22

I\'ve got a string with words that are separated by spaces (all words are unique, no duplicates). I turn this string into list:

s = \"#one cat #two dogs #th         


        
9条回答
  •  长情又很酷
    2020-11-30 14:48

    If you just need to clear the list,

    use out = [] or out.clear()

    Anyway, that you said is because remove function of list affects list.

    out = ['a', 'b', 'c', 'd', 'e', 'f']
    for x in out:
        out.remove(x)
        print(x)
    

    then result is shown below:

    a c e

    It is exactly half of full list. So, in your case, you got 96(half of 192) from 192.

提交回复
热议问题