That sort of is what I was looking for, and helped me on the way to fix it. Since the second string I wanted to find was set beforehand, I had a problem putting it directly into the regex. However, if I use your method I can fix that. Here's how I did it in the end:
That allows me to call each binary string separately with m.groups()[1] for instance, which is what I wanted. Now all I have to do is translate it to re.findall and I'm probably done, thanks
That allows me to call each binary string separately with m.groups()[1] for instance, which is what I wanted. Now all I have to do is translate it to re.findall and I'm probably done, thanks
re.finditer() is damn useful too.
Code:
import re
string="""
000101101000101101 -> 000101101110101101
000101101000101101 -> 000101101110101101
000101101000101101 -> 000101101110101101
000101101000101101 -> 000101101110101101
000101101000101101 -> 000101101110101101
"""
ideal='000101101110101101'
rexx = r'([01]+)\s->\s('+str(ideal)+')'
for m in re.finditer(rexx, string):
print m.groups()
I used to program in Lisp so I am well used to map, reduce, filter, lambda, but I know they are considered "unpythonic" because they were originally scheduled to be removed in Python 3. (In the end, only reduce was removed).
Cool, I didn't know that.
Maybe the lack of reduce is why Python 3 is having such a slow adoption rate...
I'm new to python. I downloaded it, opened IDLE, loaded the pokereval.py code in the script window, and pressed F5, but in the python shell I get an error:
Traceback (most recent call last):
File "C:\Users\[my name]\Desktop\pypoker-eval-138.0\pypoker-eval-138.0\pokereval.py", line 29, in <module>
_pokereval = __import__('_pokereval_' + sys.version[0] + '_' + sys.version[2])
ImportError: No module named _pokereval_3_2
I'm new to python. I downloaded it, opened IDLE, loaded the pokereval.py code in the script window, and pressed F5, but in the python shell I get an error:
Traceback (most recent call last):
File "C:\Users\[my name]\Desktop\pypoker-eval-138.0\pypoker-eval-138.0\pokereval.py", line 29, in <module>
_pokereval = __import__('_pokereval_' + sys.version[0] + '_' + sys.version[2])
ImportError: No module named _pokereval_3_2
Thanks.
You're getting this particular error here because your python can't find the compiled C poker-eval libraries on your computer. pypokereval is just a wrapper for poker-eval so it needs to be installed and added to the system path as well.
That being said, pypokereval is notoriously difficult to get working on Windows. I believe gimick from the fpdb project was able to get it working once. Sorrow is another good person to ask about this. GL
Interesting. So in other words I shouldn't try getting it to work?
Where else can I get a poker simulator/calculator?
Can I tell VBA or Java to run PokerStove, then I can parse the text from pokerstove.txt?
I know I can get my calculations off pro poker tools, but I want around 50,000 calculations just for one of my calculations. Is it reasonable to have my program go to their site 50,000 times at once? I'm not even sure how long this would take.
Interesting. So in other words I shouldn't try getting it to work?
Where else can I get a poker simulator/calculator?
Can I tell VBA or Java to run PokerStove, then I can parse the text from pokerstove.txt?
I know I can get my calculations off pro poker tools, but I want around 50,000 calculations just for one of my calculations. Is it reasonable to have my program go to their site 50,000 times at once? I'm not even sure how long this would take.
I'm working on the mitocw courses. Using spoilers because I don't want to give out the answer to googleBots:
Spoiler:
Most of this stuff, I was able to figure out on my own. Commented for your ease of readability and my thoughts (with no cursing).
addition: Oops, all that commenting makes the code unreadable, so there are now two code tags. The first has all my thoughts (and quick cliffs after the block), and the second is the raw code.
Code:
## find the 1000th prime, which is 7919.
## This particular answer creates a full list.
## I could easily have it print out only 7919,
## but watching the numbers accumulate is like
## watching your favorite horse at the races:
##the anticipation is the fun part, IMO. :p
## The first part is logical.
## Initialize some variables and have fun.
##At first, I was using import math and using
##int(math.sqrt(pNum)
## to create a top range number. I also externalized:
##pCount = 2
##div = int(math.sqrt(pNum))
##......
##for i in range(2,div+1):
##I had issues with this one,
##and I am sure if I wasn't sick of doing this particular problem,
##I could fix it. The issue became that I could not top out the
##counter variable to 1000.
##More specifically,
## I was getting funky answers when the
## pCount variable was set at 1000.
## Regardless, there is no need to look like a super-hero
## and use the sqrt upper-limit,
## so using pNum/2 works just as well.
## I figure it wasn't as bad as using pNum
## as the upper limit: That is just too amateur for my taste.
pCount = 2
pNum = 5
while pCount < 1000:
## It doesn't take a genius, knowing my history with programming,
## to figure out that I have no idea why I would want to initialize
## "test" inside of the function opposed to outside the function.
## Regardless, this is good to know.
## You would be shocked to know that I figured out the
## boolean with some hard thinking.
## I began with externalizing "test", but that didn't work
test = True
for i in range(2, int(pNum/2)):
if pNum%i == 0:
test = False
break
## the idea of the assignment is to figure out "flow Control"
## or in the words of
## the professor "introduce you to flow control."
## Finding out to un-nest the if
## to prevent fall-through was an amazing find
## and probably the entire point
## of the project.
if test == True:
pCount += 1
print pNum
## This part probably took more time to figure out than it should have
## (all of five minutes while picking my nose).
## At first, i commented out this region and saw a bunch of
## '5' going down the Shell.
## if pCount == 1000:
## break
## else:
## pNum += 1
## But all hope wasn't lost:
pNum += 1
Cliffs for above: I didn't figure out why 'test' has to be inside of the while block. The ultimate revelation was learning how to un-nest if statements to prevent full code fall-through.
The unabridged version:
Code:
pCount = 2
pNum = 5
while pCount < 1000:
test = True
for i in range(2, int(pNum/2)):
if pNum%i == 0:
test = False
break
if test == True:
pCount += 1
print pNum
pNum += 1
Since test is already a boolean, you don't need to compare it to True. Python, like many scripting languages, is liberal with will evaluate to true in an if clause. However, I tend to only let booleans auto evaluate for the sake of readability.
Also, loops can have an else block that executes when the loop runs to completion. I've never actually used it, but it is exactly what you are testing for.
which I guess is the same thing of sorts and serves as a better visual to why the 'test' primitive was in the block instead of outside it.
Not sure how you program without the else blocks. Are you saying you don't specify else or you really don't use it at all? I'm sort of in the habit of using indenting to execute the else opposed to actually writing else. But there are times it is handy. The next two projects are 'brute force algorithms,' which require some else blocks to execute I think, if for nothing else but to return Null values to the main functions. But, eh, I haven't put any effort into much more than a rudimentary start. Hopefully, this one won't take a week to do.
Spoilers won't hide the answer from bots by the way. It doesn't do a live call toget the spoiler contents. It just hides or shows a div that's already there.