How to a turn a list of strings into complex numbers in python?

前端 未结 5 756
刺人心
刺人心 2021-01-19 19:33

I\'m trying to write code which imports and exports lists of complex numbers in Python. So far I\'m attempting this using the csv module. I\'ve exported the data to a file u

5条回答
  •  孤独总比滥情好
    2021-01-19 20:22

    Just pass the string to complex():

    >>> complex('(37470-880j)')
    (37470-880j)
    

    Like int() it takes a string representation of a complex number and parses that. You can use map() to do so for a list:

    map(complex, row)
    

提交回复
热议问题