wordsearch

2019-11-19 Thread jezkator
Hi, I have got a problem in my searchword. Everything runs properly. Output 
writes word, coordinates and direction, but i need, that output have same 
arrangement as second file
First file includes board, where program search:
xmuinjekci
evelkochov
cadvouhrac
feminizaci
pyzlanpbik
ldvojlinky
osvrhloubd
dqldrvandy
yevergreen
olympskout

and second includes words:
dvojlinky
feminizaci
velkochov
dvouhra
olympskou
plody
dyn
rab
svrhlou
np
jo
lordem
velko
injekci
skout
mva
vandy
dvou
evergreen
ech
zla
kb
un
hrr
aj
ona

Python Code: 


def find_words(file_inputs, words):
with open(file_inputs) as file:
for line in file:
line = line.replace('\n', '')
line = line.lower()
words.append(line)
 
def get_search_board(file_inputs, search_board):
with open(file_inputs) as file:
for line in file:
if len(line) > 6:
line = line.lower()
search_board += line
length = search_board.index('\n') + 1
return search_board, length
 
def main():
words = []
search_board = ''
z = input().split()
file_input = z[0]
file_inputs = z[1]
find_words(file_inputs, words)
search_board, length = get_search_board(file_input, search_board)
lines = {}
 
lines["1"] = []
 
letters = [(letter, divmod(index, length))
   for index, letter in enumerate(search_board)]
 
lines['0'] = letters
 
for i in range(length):
for j in range(i, len(letters), length):
lines["1"].append(letters[j])
 
for direction, tuple in lines.items():
string = ''.join([i[0] for i in tuple])
for word in words:
if word in string:
coordinates = tuple[string.index(word)][1]
print(word,coordinates[0], coordinates[1], direction)
 
main()

Output:
plody 4 0 1
dyn 6 9 1
rab 2 7 1
jo 0 5 1
lordem 4 3 1
mva 0 1 1
ech 0 6 1
kb 5 8 1
un 6 7 1
hrr 6 4 1
aj 4 4 1
ona 2 4 1
dvojlinky 5 1 0
feminizaci 3 0 0
velkochov 1 1 0
dvouhra 2 2 0
olympskou 9 0 0
svrhlou 6 1 0
np 4 5 0
velko 1 1 0
injekci 0 3 0
skout 9 5 0
vandy 7 5 0
dvou 2 2 0
evergreen 8 1 0
zla 4 2 0

but i need output like this

Output:
dvojlinky 5 1 0
feminizaci 3 0 0
velkochov 1 1 0
dvouhra 2 2 0
olympskou 9 0 0
plody 4 0 1
dyn 6 9 1
rab 2 7 1
svrhlou 6 9 0
np 4 5 0
jo 0 5 1
lordem 4 3 1
velko 1 1 0
injekci 0 3 0
skout 9 5 0
mva 0 1 1
vandy 7 5 0
dvou 2 2 0
evergreen 8 1 0
ech 0 6 1
zla 4 2 0
kb 5 8 1
un 6 7 1
hrr 6 4 1
aj 4 4 1
ona 2 4 1

Can u help me please?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: wordsearch

2019-11-19 Thread jezkator
Dne úterý 19. listopadu 2019 13:33:53 UTC+1 Richard Damon napsal(a):
> On 11/19/19 6:47 AM, jezka...@gmail.com wrote:
> > Hi, I have got a problem in my searchword. Everything runs properly. Output 
> > writes word, coordinates and direction, but i need, that output have same 
> > arrangement as second file
> > First file includes board, where program search:
> 
> Look at our code, and what controls the order you data is output. Change
> it so that the data is processed in the order you want the output.
> 
> -- 
> Richard Damon

I know, that the best way, how i can learn that is by myself, but can u do that 
with my code and post here, please?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: wordsearch

2019-11-19 Thread jezkator
Dne úterý 19. listopadu 2019 17:07:36 UTC+1 Richard Damon napsal(a):
> On Nov 19, 2019, at 10:56 AM, Chris Angelico  wrote:
> > 
> > On Wed, Nov 20, 2019 at 2:46 AM  wrote:
> >> 
> >> Dne úterý 19. listopadu 2019 13:33:53 UTC+1 Richard Damon napsal(a):
>  On 11/19/19 6:47 AM, jezka...@gmail.com wrote:
> > Hi, I have got a problem in my searchword. Everything runs properly. 
> > Output writes word, coordinates and direction, but i need, that output 
> > have same arrangement as second file
> > First file includes board, where program search:
> >>> 
> >>> Look at our code, and what controls the order you data is output. Change
> >>> it so that the data is processed in the order you want the output.
> >>> 
> >>> --
> >>> Richard Damon
> >> 
> >> I know, that the best way, how i can learn that is by myself, but can u do 
> >> that with my code and post here, please?
> > 
> > Nope.
> > 
> > ChrisA
> > 
> 
> Think what order you want your output.
> Make your main loop go through the data in that order
> For each of the data, find the answer for that data
> Print the results.
> 
> You should be able to figure this out.


Ok, so first (outer) loop will be for word in words, than for direction, tuple
... But now is problem that it prints 10 times but just the last one is 
complete and ok
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: wordsearch

2019-11-19 Thread jezkator
Dne úterý 19. listopadu 2019 17:14:06 UTC+1 jezk...@gmail.com napsal(a):
> Dne úterý 19. listopadu 2019 17:07:36 UTC+1 Richard Damon napsal(a):
> > On Nov 19, 2019, at 10:56 AM, Chris Angelico  wrote:
> > > 
> > > On Wed, Nov 20, 2019 at 2:46 AM  wrote:
> > >> 
> > >> Dne úterý 19. listopadu 2019 13:33:53 UTC+1 Richard Damon napsal(a):
> >  On 11/19/19 6:47 AM, jezka...@gmail.com wrote:
> > > Hi, I have got a problem in my searchword. Everything runs properly. 
> > > Output writes word, coordinates and direction, but i need, that 
> > > output have same arrangement as second file
> > > First file includes board, where program search:
> > >>> 
> > >>> Look at our code, and what controls the order you data is output. Change
> > >>> it so that the data is processed in the order you want the output.
> > >>> 
> > >>> --
> > >>> Richard Damon
> > >> 
> > >> I know, that the best way, how i can learn that is by myself, but can u 
> > >> do that with my code and post here, please?
> > > 
> > > Nope.
> > > 
> > > ChrisA
> > > 
> > 
> > Think what order you want your output.
> > Make your main loop go through the data in that order
> > For each of the data, find the answer for that data
> > Print the results.
> > 
> > You should be able to figure this out.
> 
> 
> Ok, so first (outer) loop will be for word in words, than for direction, tuple
> ... But now is problem that it prints 10 times but just the last one is 
> complete and ok

OK, I got it, thnx for help
-- 
https://mail.python.org/mailman/listinfo/python-list


python 3 prefix to infix without too many parethesis

2019-12-09 Thread jezkator
Hi, I have got a problem.
I wrote a code for prefix to infix. It works, but I need improve it
so on input there will be only necessary parentheses. Can u help me?
Here is the code:

import re
a = input()

class Calculator:

def __init__ (self):
self.stack = []

def push (self, p):
if p in ['+', '-', '*', '/', "**"]:
op1 = self.stack.pop ()
op2 = self.stack.pop ()
self.stack.append ('(%s%s%s)' % (op1, p, op2))


print("op1 =", op1)
print("op2 =", op2)
print("p=", p)
print(self.stack)

else:
self.stack.append (p)


def convert (self, l):
l.reverse ()
for e in l:
self.push (e)
return self.stack.pop ()

c = Calculator ()

print (c.convert (re.findall(r'\d+|\*\*|[-+*/]', a)))


input is like /-*+*++**85 27 39 87 65 65 37 63 91

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: heap enhancements

2020-01-03 Thread jezkator
ok, so it could be like this?

import sys
chain = sys.stdin.read().splitlines()
array_z = list()
for line in chain:
row=list(map(str, line.split()))
array_z.append(row)
#every line in input changes into 2D array

def checking(chain):
"checking if characters are numbers or not"
for char in chain:
if char not in "0123456789-":
return False
return True

class MaxHeap:
def __init__(self):
"""heap __init__ constructor"""
self.heap =[]
def bubble_up(self, i):
bubble the element up if condition is ok """
while i > 0:
j = (i - 1) // 2
if self.heap[i] <= self.heap[j]:
break
self.heap[j], self.heap[i] = self.heap[i], self.heap[j]
i = j
def insert(self, k):
"""insert element in heap"""
self.heap += [k]
self.bubble_up(len(self.heap) - 1)
def peek(self):
"""return the biggest element"""
return self.heap[0]
def size(self):
"""return quantity of elements in heap"""
return len(self.heap)
def is_empty(self):
"""is heap empty?"""
return self.size() == 0
def bubble_down(self, i):
"""bubble down the element"""
n = self.size()
while 2 * i + 1 < n:
j = 2 * i + 1
if j + 1 < n and self.heap[j] < self.heap[j + 1]:
j += 1
if self.heap[i] < self.heap[j]:
self.heap[i], self.heap[j] = self.heap[j], self.heap[i]
i = j
def pop(self):
"""delete the biggest element and change the heap"""
element = self.heap[0]
self.heap[0] = self.heap[-1]
self.heap.pop()
self.bubble_down(0)
return element

for i in range (len( array_z)):
for j in range (len( array_z[i])):
digit_z= array_z[i][j]
if digit_z.isdigit() is True:
array_z[i][j]=int( array_z[i][j])
check =checking(digit_z)
if check is True:
array_z[i][j]=int( array_z[i][j])

Heap=MaxHeap()
for a in range (len( array_z)):
if  array_z[a][0]>0:
Heap.insert( array_z[a])
if  array_z[a][0] < 0:
print( array_z[a][1]+": ",end="") #print name of delivery
index_of_package= array_z[a][0]
while index_of_package<0 and (Heap.is_empty()) is False:
delivery_package=Heap.pop()
print(delivery_package[1],end=" ") #print name of package in 
delivery
index_of_package+= 1
print("")
print("Depo: ",end="")
while (Heap.is_empty()) is False:
depo_package=Heap.pop()
print(depo_package[1],end=" ") #print name of package in depo
-- 
https://mail.python.org/mailman/listinfo/python-list