Skip to content

Instantly share code, notes, and snippets.

@spdin
Last active January 16, 2020 03:35
Show Gist options
  • Select an option

  • Save spdin/7665fb0814bffca9eabae32537d15b50 to your computer and use it in GitHub Desktop.

Select an option

Save spdin/7665fb0814bffca9eabae32537d15b50 to your computer and use it in GitHub Desktop.
List of collection of Python Snippet
# get actual name of file before extension
file = 'my.report.txt'
print file.rsplit('.', 1)[0]
# list of comprehension
words = [w.replace('[br]', '<br />') for w in words]
# get intersection of list
def intersection(lst1, lst2):
temp = set(lst2)
lst3 = [value for value in lst1 if value in temp]
return lst3
# get k random sample from list
import random
sample_file = random.sample(allfile, 1000)
# get list of text
with open('test.txt', 'r') as f:
list_file = [line.strip() for line in f]
f_inv = []
for f in list_file:
f_s = f.split(' ')
kelas = f_s[1]
if kelas == '11':
f_inv.append(f_s[0])
# copy file to folder, if to file, use shutil.copyfile()
for f in f_inv:
shutil.copy('../images/'+f,'invoices_test/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment