I have a list that is has a pattern like this [float, string, float string...] but occasionally in the pattern it changes to [float, string, float, string, string, float string...]. What I want to do is to extract the elements of the list to a tuple in the format of (float, name, NoneType or str) to do something with it later. Here is a small example:
arr = [1150.1, 'James', 3323.1, 'Steve', 9323.1, 'John', 1233.1, 'Gary', 'criminal', 3293.1, 'Josh', 9232.1, 'Daniel', 'criminal']
I want to extract the list so the tuples look like this:
(1150.1, James, NONE)
(3323.1, Steve, NONE)
(9323.1, John, NONE)
(1233.1, Gary, criminal)
(3293.1, Josh, NONE)
(9232.1, Daniel, criminal)
so far i've tried checking for the next index in the array for the type but it's not working:
for index in range(len(arr)):
if type(arr[index]) == float and type(arr[index+1]) == str:
tup = arr[index], arr[index+1], None
print(tup)
elif type(arr[index]) == float and type(arr[index+1]) == str and type(arr[index+2]) == str:
tup = arr[index], arr[index + 1], arr[index+2]
print(tup)