Reputation: 853
I have a list
list = ['i-052b7c00040cad9e8', 1.53, 86.7265358899962, '/', 25.1078055963193, '/run', 10.6200969763866, 'i-0f40cbf93afdb6949', 1.97, 86.6133940961272, '/', 24.2470470317567, '/dev', 0.0]
I want to split list in every i-xxxxx and store all separated list in a single list.
Thanks in advance :)
Upvotes: 1
Views: 92
Reputation: 4814
Here is the Python 3 code (it should work)
newList = []
tempA = []
for item in list:
if "i-" in str(item) and len(tempA) == 0:
tempA.append(item)
elif "i-" in str(item) and len(tempA) != 0:
newList.append(tempA)
tempA = [item]
else:
tempA.append(item)
newList contains the list of lists.
PS: Next time, post whatever code you have tried and then seek help. Right now, it seems like you haven't tried and just want the code.
Upvotes: 1