How to optimize this Python code (from ThinkPython, Exercise 10.10)

前端 未结 4 853
无人共我
无人共我 2021-01-12 00:54

I\'m working through Allen Downey\'s How To Think Like A Computer Scientist, and I\'ve written what I believe to be a functionally correct solution to Exercise 10.1

4条回答
  •  悲&欢浪女
    2021-01-12 01:46

    Alternative definition for interlock:

    import itertools
    
    def interlock(str1, str2):
        "Takes two strings of equal length and 'interlocks' them."
        return ''.join(itertools.chain(*zip(str1, str2)))
    

提交回复
热议问题