Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> l1 = ["1" ,"2"]
- >>> l2 = "3;4"
- >>> l3 = ["5", "6"]
- >>>
- >>> for x in [l1, l2, l3]:
- print("Working on: {}".format(x))
- if isinstance(x, basestring):
- x = x.split(";")
- print("New x: {}".format(x))
- else:
- print("Its same")
- Working on: ['1', '2']
- Its same
- Working on: 3;4
- New x: ['3', '4']
- Working on: ['5', '6']
- Its same
- >>> l1, l2, l3
- (['1', '2'], '3;4', ['5', '6'])
- >>> l1, l2, l3
- (['1', '2'], ['3', '4'], ['5', '6'])
- x = x.split(";")
- def splitter(x):
- print("Working on: {}".format(x))
- if isinstance(x, basestring):
- x = x.split(";")
- print("New x: {}".format(x))
- else:
- print("It's the same")
- return x
- l1 = splitter(l1)
- l2 = splitter(l2)
- l3 = splitter(l3)
- l1, l2, l3 = [splitter(x) for x in [l1, l2, l3]]
- vals = [l1, l2, l3] # create list
- for i, x in enumerate(vals): # iterate through list
- vals[i] = splitter(x) # modify list
- l1, l2, l3 = vals # unpack list
- l1,l2,l3 = [i.split(';') if isinstance(i, basestring) else i for i in [l1,l2,l3]]
- >>> print l1, l2, l3
- ['1', '2'], ['3', '4'], ['5', '6']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement