How to use not_have method in Sure

Best Python code snippet using sure_python

wordle_solver.py

Source:wordle_solver.py Github

copy

Full Screen

1import re2import numpy as np3from random import choice4from itertools import product5from nltk.corpus import words6from Levenshtein import distance7def preprocessing():8 dict_words = {}9 for word in words.words():10 if len(word) not in dict_words:11 dict_words[len(word)] = [word.lower()]12 else:13 dict_words[len(word)].append(word.lower())14 15 return dict_words16def initial_guess(word_list):17 points = np.zeros((len(word_list)))18 for i, word in enumerate(word_list):19 if 'a' in word:20 points[i] += 121 22 if 'e' in word:23 points[i] += 124 25 if 'i' in word:26 points[i] += 127 28 if 'o' in word:29 points[i] += 130 31 if 'u' in word:32 points[i] += 133 34 max_point = np.max(points)35 positions = np.where(points == max_point)36 suggestions = []37 for pos in positions:38 suggestions += [word_list[pos[0]]]39 40 return choice(suggestions)41def choose_word(word_list, have = {}, not_have = [' '], form = None):42 if form == None:43 n = str(len(word_list[0]))44 form = '\S{' + n + '}'45 46 suggests = []47 word_list = [word for word in re.findall(form, ' '.join(word_list))]48 if word_list == []:49 return None50 51 if ' ' not in not_have:52 not_have.append(' ')53 54 for word in word_list:55 out = False56 for letter in have.keys():57 if letter in not_have:58 not_have.remove(letter)59 60 if word.count(letter) < have[letter]:61 out = True62 63 for letter in not_have:64 if letter in word:65 out = True66 67 if not out:68 suggests += [word]69 70 if suggests == []:71 return None72 73 return choice(suggests)74def solve():75 n = int(input('How many letters have the word?\n'))76 t = int(input('How many turns do you have?\n'))77 words = preprocessing()78 words = words[n]79 turns = 080 have = {}81 not_have = []82 form = '.' * n83 while turns < t:84 signal = ''85 while not signal.startswith('y'):86 if signal.startswith('n'):87 words.remove(guess)88 89 if turns == 0:90 guess = initial_guess(words)91 else:92 guess = choose_word(words, have = have, not_have = not_have, form = form)93 94 print()95 print(f'My guess is the word: {guess}')96 print()97 98 signal = input('Did this guess work? [y/n]\n').lower()99 100 included = []101 for pos, letter in enumerate(guess):102 ans = input(f'The letter {letter} is in the secret word? [y/n]\n').lower()103 if ans.startswith('n'):104 not_have.append(letter)105 else:106 if letter in included:107 have[letter] += 1108 else:109 have[letter] = 1110 included.append(letter)111 112 ans = input('Is this letter in its real position? [y/n]\n')113 if ans.startswith('y'):114 form = form[:pos] + letter + form[pos + 1:]115 116 words.remove(guess)117 if '.' not in form:118 return form119 120 turns += 1121def choose_word_re(word_list, possibilities, have = {}):122 suggests = []123 word_list = [word for word in re.findall(''.join(possibilities), ' '.join(word_list))]124 if word_list == []:125 return None126 127 for word in word_list:128 out = False129 for letter in have.keys():130 if word.count(letter) < have[letter]:131 out = True132 133 if not out:134 suggests += [word]135 136 if suggests == []:137 return None138 139 return choice(suggests)140def smart_solve():141 n = int(input('How many letters have the word?\n'))142 t = int(input('How many turns do you have?\n'))143 possibilities = ['[qwertyuiopasdfghjklzxcvbnm]' for i in range(n)]144 words = preprocessing()145 words = words[n]146 turns = 0147 have = {}148 form = '.' * n149 while turns < t:150 signal = ''151 while not signal.startswith('y'):152 if signal.startswith('n'):153 words.remove(guess)154 155 if turns == 0:156 guess = initial_guess(words)157 else:158 guess = choose_word_re(words, possibilities, have = have)159 160 print()161 print(f'My guess is the word: {guess}')162 print()163 164 signal = input('Did this guess work? [y/n]\n').lower()165 166 included = []167 for pos, letter in enumerate(guess):168 ans = input(f'The letter {letter} is in the secret word? [y/n]\n').lower()169 if ans.startswith('n'):170 aux = list(possibilities[pos])171 aux.remove(letter)172 possibilities[pos] = ''.join(aux)173 else:174 if letter in included:175 have[letter] += 1176 else:177 have[letter] = 1178 included.append(letter)179 180 ans = input('Is this letter in its real position? [y/n]\n')181 if ans.startswith('y'):182 possibilities[pos] = letter183 else:184 aux = list(possibilities[pos])185 aux.remove(letter)186 possibilities[pos] = ''.join(aux)187 188 words.remove(guess)189 if len(''.join(possibilities)) == n:190 return ''.join(possibilities)191 192 turns += 1...

Full Screen

Full Screen

create_local_HCP_db.py

Source:create_local_HCP_db.py Github

copy

Full Screen

1import sqlite32import os3from Bio import SeqIO4db ="/home/yangfang/PhySpeTree/physpetools/physpetool/database/KEGG_DB_3.0.db"5conn = sqlite3.connect(db)6conn.text_factory = str7c = conn.cursor()8c.execute("select * from proindex")9x = c.fetchall()10def read_seq(seq_path):11 seq_db = {}12 reads = SeqIO.parse(seq_path, 'fasta')13 for read in reads:14 seq = str(read.seq)15 seq_name = str(read.name)16 tem = seq_name.strip().split("|")17 if len(tem) > 1:18 seq_name = tem[1]19 seq_db[seq_name] = seq20 return seq_db21total = []22not_have = []23HCP_db = "/home/yangfang/PhySpeTree/revision/HCPDB/hcpdb/"24db_path = "/home/yangfang/PhySpeTree/revision/HCPDB/abb_seqs1000/"25all_ = len(x)26idx =127for line in x:28 tem = [var for var in line if var != None]29 spe_name = tem[1]30 seq_name = tem[2:]31 read_path = db_path + spe_name + ".fasta"32 if os.path.isfile(read_path):33 seqs = read_seq(read_path)34 for each in seq_name:35 if each in seqs.keys():36 w_path = HCP_db + each + ".fasta"37 # print(w_path)38 f_w = open(w_path,'w')39 f_w.write(">" + each +"\n" + seqs[each])40 f_w.close()41 else:42 not_have.append(each)43 else:44 not_have.extend(seq_name)45 idx +=146 print(idx/all_)47with open("/home/yangfang/PhySpeTree/revision/HCPDB/hcp_code.txt",'w') as f:48 for each in not_have:...

Full Screen

Full Screen

mysqlutils.py

Source:mysqlutils.py Github

copy

Full Screen

1#!/usr/bin/env python32import pymysql3import config4# get all tables names from database - return tables as array | return false5def getAllTablesFromDb():6 try:7 db = pymysql.connect(host=config.mysql_host,user=config.mysql_db_user,password=config.mysql_db_password,database=config.mysql_db_name,charset='utf8mb4')8 cursor = db.cursor()9 cursor.execute("SHOW TABLES")10 data = cursor.fetchall()11 tables = []12 for row in data:13 tables+=row14 return (tables)15 except:16 print ('Error! can\'t fetch data from database')17 return False18# check if tables which we need to check is exists in database - return true if all tables exists | return array of tables which not in db19def checkTablesIsExists(tables):20 print(tables)21 alltables = getAllTablesFromDb()22 if alltables != False:23 checktables = tables.get('tables').split(',')24 not_have = []25 for tab in checktables:26 if tab not in alltables:27 not_have.append(tab)28 else:29 pass30 if len(not_have) > 0:31 return ','.join([str(elem) for elem in not_have])32 else:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Sure automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful