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.
The code practically unreadable. Why use a name like mtch instead of matches or even just match? Is it really so hard to type those extra letters? The difference in the readability of code when you use actual words versus unreadable contractions is HUGE. Please do yourself and others a favor and spend a few minutes to spell that out at least.
And while you're at it, spell out "vrsta" as well. Better yet, translate it to an English word for the folks here.
The result of calling match() on a regular expression is a match object, which is always true, or None. You use the and Boolean operator though. It seems to me that if both calls to match() succeed, then the mtch variable will be a plain Boolean value of true rather than a match object. I could be wrong though. If it is indeed just a Boolean true value, what happens when you get to mtch.group()?
Edit: Ok, I'll answer my own question. Apparently, the expression r_inf_5a.match(element) and r_pz_5a.match(element) evaluates to the match object returned by the second term, r_pz_5a.match(element), if the first term matches.
So as I understand it now, the intent of that code is to replace the pair with just the element of the tuple/pair when both elements match their respective regexs.
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.