This week's book giveaway is in the Open Source forum.
We're giving away four copies of Programmers Guide to Apache Thrift and have Randy Abernethy on-line!
See this thread for details.
Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!

M. Gumblert

Ranch Hand
+ Follow
since Sep 15, 2018
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by M. Gumblert

Hello everyone!
I have some problems with a program I am writing.

Description of the program: I have a list of verbs (var all_verbs) and would like to compare them to a list elements that is in .gz file format("ex_v1.3.gz"). The ex_v1.3gz files looks like this:

word \t the dictionary form of the word \t morphological characteristics of the word
word1 \t the same dictionary form of the word \t morphological characteristics of the word
word2 \t the same dictionary form of the word \t morphological characteristics of the word
...
word \t the dictionary form of the word(not the same as above) \t morphological characteristics of the word
word1 \t the same dictionary form of the word \t morphological characteristics of the word
word2 \t the same dictionary form of the word \t morphological characteristics of the word
...

Now if a verb from svi_glagoli is equal to a dictionary form of the word from the .gz file then I want to find out what does the word form looks if its morphological characteristics are (for example: xy) and then write it in a .txt file. Here is an example (kinda hard with english because it isn't a proper flective language):
My verb is "to run". I want to write in the .txt "to run" and the form of this word that is used for third-person singular. The program now loops through the .gz file and find the line where the dictionary form is "to run", then looks for the morphological characteristics for third-person singular and then if everything matches writes the word form that is found in that line(i.e. runs)


I am not sure, that this method is logically a good one. I am pretty sure it's really slow (the .gz file is huge and it has to loop through it everytime). Anyway, it looks like this. In my previous topics, some people mentioned that my codes are unreadable, I hope it is better now.
My code:



In the code, this line.split("\t")[0] is the word, and line.split("\t")[2] == "xy" is the morphological characteristic.
My problem is that nothing happens. The verb.txt file is empty. If I test my program with a print() method it goeso n for some time then stops. Counted the loops in the nested loop = 6427709, in the outside loop = 3000 (The verbs list contains 3000 elements). The loop is working I guess, but it doesn't do anything.
Also, can you help me how to change this:



into something easier, a oneliner.

I know it is a long post, thank you, in advance, for your help.
4 weeks ago
I was in a rush and completely forgot to answer you. I managed to correct my program using list comprehension. Is´s much more easier and is working perfectly fine now. I am not sure why you said my code is unreanable. As I said I didn´t want to rename the variables because I was afraid I might break the code. Anyway, thank you.
4 weeks ago


Hello. This is my code. It is kind of hard to explain, because this is just a segment of the program. The basic principle is that i have this list cijela_lista_bez_duplikata that has 2003 elements in it. I am using regex to sort the elements.  The problem is that once i put "cijela_lista_bez_duplikata.remove(element)" on the end of each sorting the result changes. Which is very strange because regexis shouldn't overlap (There is a tiny overlap, but nothing signifacnt). I am "losing" 200 elements in 5a.
I am not sure if you guys understand what I am trying to do.
For reference, the strings in cijela_lista_bez_duplikata look like this: ('mislim', 'misliti'), ('znam', 'znati'), ('imam', 'imati'), ('vidim', 'vidjeti'), ('moram', 'morati'), ('mogu', 'moći'), ('želim', 'željeti')...

I didn't translate the code, because I would probably mess up everything.
1 month ago
@Travis Risner
Thank you for your long answer I will try to rewrite the code.
@Liutauras Vilda
Thank you for your answers and pointing out the problems with split(","). I know that there are some logical problems (like the 110kg thing). I didn't bother with that because those are some problems I will look into later.
2 months ago
Dear everyone,

thank you for your help. As most of you suggested I translated the code. Ignore the one I started the topic with. Here is the whole code. The idea is a really basic program that counts how much kcal you can eat a day. When you type in your meal in the format: "salad, 300" the program adds that to a list, and takes 300 from your daily kcal that is defined based on your weight. All the numbers are arbitrary. The problem remains the same:

kcal_limit = kcal_limit - int(meal[1])
IndexError: list index out of range

Here is the code:
2 months ago
Oh sorry, I was translating the code for english speakers. It's the "food"
2 months ago
Hello everyone.
Could someone tell me why isn't my code working?



So the program is like a conceptual fitness app. where the user types in the food he ate and its kcal and separates it with a ",". The kcal of the eaten food is then taken from the limit. Everything is stored in a list (for statistics or whatever). This goes on until the user says "thatsit". Then the it breaks out of the while loop and prints out the list and the remaining kcal for the day (this is shown, after every input).
Everything goes fine until I want to finish the input.

   limit = limit - int(food[1])
IndexError: list index out of range

Also, would it be smarter to store the eaten food in touples instead of lists in a list.
2 months ago
Okay, I am not sure what you are saying. Does this mean that the code is right? There shouldn't be any problems with the .txt file as well. What can I do?
3 months ago
Hello, I am in the process of learning Python 3 for the purposes of NLP.
I am trying to work with a .txt that has non-ASCII characters. In the exercise I have to demonstrate the differences in the length of documents. My code looks like this



I understand what the lines do, I checked the solved exercise, and It is the same as this, but for some reason it won´t compile.
I get the following error message:
Traceback (most recent call last):
 File "C:...my folders...", line 56, in <module>
   print (len(open('hr.txt').read()))
 File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\encodings\cp1250.py", line 23, in decode
   return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 88422: character maps to <undefined>

Can someone help me out?
3 months ago
Thank you for your answers. The class without a method was really stupid of me. I know the names are kinda, as you said, goofy, but I just wanted to try out the very last thing i learnt.
As for the scanner I am going to study the thread you suggested.

Once again, appriciate the answers.
7 months ago
I do not exactly get either of the things you guys suggested. What should I provide a constructor to? As for the Scanner. Would it work the way I did it? If I make it a constant, how do I call it?
Am I just calling it like:
firstinput = KEYBOARD.nextInt();
secondinput = KEYBOARD.nextLine();
and so on?
7 months ago
Hello guys! I am trying to build a mini-program that allows is registering users. It asks for a username and password. The input is checked and if everything is correct the program ads the registered user to an ArrayList that holds Users


This is where I get the error messages:


I get the following error messages:

Registration.java:59: error: <identifier> expected
System.out.println("You have to have a username, it cannot be nothing - this message is from the class");
Registration.java:59: error: illegal start of type
System.out.println("You have to have a username, it cannot be nothing - this message is from the class");
Registration.java:63: error: <identifier> expected
System.out.println("You have to have a password, it cannot be 0 - this message is from the class");
Registration.java:63: error: illegal start of type
System.out.println("You have to have a password, it cannot be 0 - this message is from the class");

I am new to exceptions (and to java in general). Please correct every mistake I have. I know on some spots the logic isn't really at the top, but if I debug this I will work on that as well.

7 months ago
@Junilu Lacar

I was trying to simulate a situatuion where i try to pull infromation about a students perfomance on a course. The result should have been named grade. In my opinion it is not neccessary to make objects that hold references to other objects, but I was just wondering how is that possibble. I admit that perhaps this isn't the best representation, but I thought that it will be easier to ask a question providing a little context on what I am experimenting with.

Also I wanted to see the logic what is behind the "object that holds references to objects" is.

@everyone

Thank you for your answers.
7 months ago
So I am a bit of a struggle.

I want to make a class that is named results. It would hold the proffessor, the student and the result. The only problem is that proffessor and student are object with their own instances and methods. I want to put classes into a class.
I was wondering how is this possibble.
Should I try to put them into an ArrayList<Object> or what is the right way to do it?
7 months ago
it is from 148 to 153
8 months ago