Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. >>> l1 = ["1" ,"2"]
  2. >>> l2 = "3;4"
  3. >>> l3 = ["5", "6"]
  4. >>>
  5. >>> for x in [l1, l2, l3]:
  6. print("Working on: {}".format(x))
  7. if isinstance(x, basestring):
  8. x = x.split(";")
  9. print("New x: {}".format(x))
  10. else:
  11. print("Its same")
  12.  
  13.  
  14. Working on: ['1', '2']
  15. Its same
  16. Working on: 3;4
  17. New x: ['3', '4']
  18. Working on: ['5', '6']
  19. Its same
  20. >>> l1, l2, l3
  21. (['1', '2'], '3;4', ['5', '6'])
  22.  
  23. >>> l1, l2, l3
  24. (['1', '2'], ['3', '4'], ['5', '6'])
  25.  
  26. x = x.split(";")
  27.  
  28. def splitter(x):
  29. print("Working on: {}".format(x))
  30. if isinstance(x, basestring):
  31. x = x.split(";")
  32. print("New x: {}".format(x))
  33. else:
  34. print("It's the same")
  35. return x
  36.  
  37. l1 = splitter(l1)
  38. l2 = splitter(l2)
  39. l3 = splitter(l3)
  40.  
  41. l1, l2, l3 = [splitter(x) for x in [l1, l2, l3]]
  42.  
  43. vals = [l1, l2, l3] # create list
  44. for i, x in enumerate(vals): # iterate through list
  45. vals[i] = splitter(x) # modify list
  46. l1, l2, l3 = vals # unpack list
  47.  
  48. l1,l2,l3 = [i.split(';') if isinstance(i, basestring) else i for i in [l1,l2,l3]]
  49.  
  50. >>> print l1, l2, l3
  51. ['1', '2'], ['3', '4'], ['5', '6']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement