Skip to content

Instantly share code, notes, and snippets.

@dineshvg
Created April 8, 2017 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dineshvg/939e6099236300ed225803c60aabc939 to your computer and use it in GitHub Desktop.
Save dineshvg/939e6099236300ed225803c60aabc939 to your computer and use it in GitHub Desktop.
Code picks every letter in the list and puts it in test and the rest in train. It does this for the entire list till the end.
## Code picks every letter in the list and puts it in test and the rest in train. It does this for the entire list till the end.
from collections import Counter
# a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
# Code for splitting training and testing
test = []
train = []
for i in range(0, len(a)):
if bool(test) is False:
test.insert(1, a[i])
print('test inserted', test)
if test[0] == a[i]:
for ii in range(a.index(a[i]), len(a)):
check = Counter(a[ii]) == Counter(test[0])
if check is False:
train.append(a[ii])
train = list(train) + list(a[a.index(a[0]):a.index(test[0])])
print('train', train)
test = []
train = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment