Lucky, have you gotten anywhere with this?

My code is the same code from the lecture notes, in terms of the load graph functions and everything. The aboce code break because there are 6 connected nodes in the graph, and then two nodes which are connected to eachother but no other nodes. When counting, the count should print 6, but it prints 3. If it printed 6, we could conclude that the graph is not ocnnected, because the total number of nodes is 8.

Ok, I found out that this code break if you use the graph like on the HW pdf. That is if the graph looks like:
A: C
C: A, F, D
F: C
D: C, B, G
B: D
G: D
E: H
H: E

Hey guys, I am working on this too. The first thing I see wrong with this code is that your for loop is running through the graph. The pseudo code says it should be running thorugh the list of neighbors for the node that is input.

Try this:
[CODE]
def DFSnodewithDeletion(graph,node)
count = 1
for i in node.neighbors:
node.neighbors.remove(i)
i.neighbors.remove(node)
count = count + DFSnodeWithDeletion(graph,i)
[/CODE]

If your graph is connected I think it return the total number of nodes. Play around with it and let me know what happens.

[QUOTE=tonyjv;1347191]This my try seems to work, I do not know if I am overcomplicating things, but you could compare this to your try and maybe debug the problem:
[CODE]from future import print_function

def match_pat(CH, mystring):
print ("%r vs %r" % (CH, mystring))
if not CH:
return not mystring
elif CH == '':
return True
elif not mystring:
return False
elif CH[0] == '
':
return any(match_pat(CH[1:],mystring[index:]) for index in range(len(mystring)))
else:
return CH[0] == mystring[0] and match_pat(CH[1:], mystring[1:])

pat = 'aatr'
for word in ("anteater",'albatross','albania'):
print(word, pat, match_pat(pat,word))
print('-'
30)
[/CODE][/QUOTE]

This code is great and works fine. The only problem is with line 12 I believe it is where you say:
[code]return any(match_pat(CH[1:],mystring[index:]) for index in range(len(mystring)))[/code]

Is there any way to change this line so it doesn't use a for loop or the any operator? Both of these are not allowed in the final submission.

I am stuck on my python lab from this week. The lab deals with strings and being able to search them, slice them, etc. The part I'm stuck on is as follows:

"You will implement in Python a function matchPat. It will take two arguments, a pattern string and a string, and return a Boolean, which indicates whether or not the pattern matches the initial portion of the string. A wild-card match is represented by an asterisk(*). HINT: You should express the algorithm recursively. Again, a good place to start is nesting the structural pattern. For the wild card, try to translate "zero or more characters" into code. Both logical operators and and or are useful."

So basically, I know where to start and what to do for the code itself, what I am having trouble doing is figuring out how to get the * to match "zero or more characters."

A few quick examples to make the question clear:

matchPat('atr', 'anteaters')
True
matchPat('atr', 'albatross')
True
matchPat('atr', 'artist')
False

This code must be done recursively using if statements and can not include the integrated python function 'in'.