Your expected output is a list of tuples which you can get with zip
, str.split
and using iter
which is more efficient than slicing.
FuntionStr='AccName,S,Balance,N,AccrInterest,N'
it = iter(FuntionStr.split(","))
print(list(zip(it,it)))
[('AccName', 'S'), ('Balance', 'N'), ('AccrInterest', 'N')]
If you have an uneven length list after splitting and you don't want to lose any data you can use zip_longest
:
FuntionStr='AccName,S,Balance,N,AccrInterest,N,foo'
it = iter(FuntionStr.split(","))
from itertools import zip_longest
print(list(zip_longest(it, it,fillvalue="")))]
('AccName', 'S'), ('Balance', 'N'), ('AccrInterest', 'N'), ('foo', '')]