Dec-07-2019, 02:06 PM
you break a string with split: https://docs.python.org/3.8/library/stdt...#str.split
conversion can be done using a dictionary: https://docs.python.org/3/tutorial/datas...ctionaries
examples:
split:
conversion can be done using a dictionary: https://docs.python.org/3/tutorial/datas...ctionaries
examples:
split:
>>> mystr = "Time is never lost - it's just replaced" >>> mylist = mystr.split() >>> mylist >>> mystr = "Time is never lost - it's just misplaced" >>> mylist = mystr.split() >>> mylist ['Time', 'is', 'never', 'lost', '-', "it's", 'just', 'misplaced'] >>> mylist[3] 'lost' >>>dictionary:
>>> fruit_color = { ... 'apple': 'red', ... 'orange': 'orange', ... 'banana': 'yellow' ... } >>> >>> print(f"An apple is {fruit_color['apple']}") An apple is red >>>