[Python] How can I change this script from Java to Python?

Discussão em 'Python' iniciado por Stack, Maio 11, 2025.

  1. Stack

    Stack Membro Participativo

    I was trying to transform this script from Java to Python, but I'm facing some technical issues to understand Java's code.

    The first class is a simple class, the name of it is a table.

    class Table:

    def __init__(self, name, number_tuple, size_tuple, nature):
    self.__name = name
    self.__number_tuple = number_tuple
    self.__size_tuple = size_tuple
    self.__nature = nature

    def get_name(self):
    return self.__name

    def set_name(self, name):
    self.__name = name

    def get_number_tuple(self):
    return self.__number_tuple

    def set_number_tuple(self, number_tuple):
    self.__number_tuple = number_tuple

    def get_size_tuple(self):
    return self.__size_tuple

    def set_size_tuple(self, size_tuple):
    self.__size_tuple = size_tuple

    def get_nature(self):
    return self.__nature

    def set_nature(self, nature):
    self.__nature = nature


    The second class is the parser class, which I'm facing trouble to change it. the first code is on java:

    public class Parser {

    Map<Integer, Table> tables;

    public Table searchTableByValue(String value) {

    Map<Integer, Table> result = this.tables.entrySet().stream()
    .filter(
    map -> value.equals(
    ((Table)map.getValue()).getName()
    ))
    .collect(
    Collectors.toMap(
    p -> (Integer)p.getKey(), p -> (Table)p.getValue()
    ));

    return (Table)result.values().toArray()[0];
    }


    The issue that I can't understand to transform is:

    map -> value.equals(((Table)map.getValue()).getName()))


    I have tried to work on Python, but I didn't do much, the code is below

    from operator import eq
    from lazy_streams import stream
    class Parser:

    self.tables = tables

    def is_equal(self, first, second):
    return eq(first, second)

    def search_table_by_value(self, value):

    cond = list(map(self.is_equal,value, (self.tables.values()).get_name()))

    result = stream(self.tables.copy().values()) \
    .filter(cond) \

    return result[0]

    Continue reading...

Compartilhe esta Página