Last active
January 16, 2020 03:35
-
-
Save spdin/7665fb0814bffca9eabae32537d15b50 to your computer and use it in GitHub Desktop.
List of collection of Python Snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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