I'm trying to create a function that will split a string into items and then split those items further into subitems and do this continuously until it runs out of arguments.
For example, I want to first split the following string by commas, and then split by lines, and then split by exclamation marks, and then split by the letter b. That is four splits.
s = 'abcde,abcde|abcde!abcde,abcde|abcde!abcde,abcde|abcde!abcde,abcde|abcde!abcde,abcde|abcde!abcde,abcde|abcde!abcde,abcde|abcde!abcde,abcde|abcde!'
Using the following I can get the desired result:
split1 = s.split(',')
split2 = map(lambda i:i.split("|"),split1)
split3 = map(lambda i: map(lambda subitem: subitem.split("!"),i),split2)
split4 = map(lambda i: map(lambda subitem: map(lambda subsubitem: subsubitem.split("b") ,subitem),i),split3)
Result:
[[[['a', 'cde']]],
[[['a', 'cde']], [['a', 'cde'], ['a', 'cde']]],
[[['a', 'cde']], [['a', 'cde'], ['a', 'cde']]],
[[['a', 'cde']], [['a', 'cde'], ['a', 'cde']]],
[[['a', 'cde']], [['a', 'cde'], ['a', 'cde']]],
[[['a', 'cde']], [['a', 'cde'], ['a', 'cde']]],
[[['a', 'cde']], [['a', 'cde'], ['a', 'cde']]],
[[['a', 'cde']], [['a', 'cde'], ['a', 'cde']]],
[[['a', 'cde']], [['a', 'cde'], ['']]]]
However, I'd like to write a function that can carry out this whole process and take in an arbitrary number of arguments. In other words, the function could carry out the above process, but only split for the exclamation mark and line or split for any number of items.
How can I make a function that does the above process but looks like this?
func(s,*args)
so that it could execute the following to accomplish the same result as above.
func(s,",","|","!","b")