私はこのコードを実行すると、なぜ私の "count"変数が0のままであるのか理解しようと、過去1時間に苦労しました。なぜ私のカウント値は0のままですか?
def main():
print "There are %s Instagram Routes in the DB" % db.routes.count()
results = defaultdict(dict)
d= 1.5 #distance
t= 4*3600 #in seconds
# For each route a_route in db.routes
print "Start of for each route for loop"
all_routes = db.routes.find().limit(5)
for a_route in all_routes:
print "restart"
# for a set of size 1 to N:
for i in range(1,a_route['n_points']+1):
# Create set of size n
set_of_size_i_pts = select_points(a_route,i)
# Calcalute the number of possible routes for the set
x_route = find_routes(set_of_size_i_pts,t,d)
x_length = len(set_of_size_i_pts)
results[a_route['_id']].update({x_length:x_route})
print results
def select_points(a_route,i):
pts = a_route['points']
return random.sample(pts,i)
def find_routes(set_of_size_i_pts,t,d):
all_routes = db.routes.find().limit(5)
count = 0
for a_route in all_routes:
if is_legitimate_route(set_of_size_i_pts,a_route,t,d):
print "hel"
count+=1
print "count: %s" % count
b = 6
print b
return count
出力:
r
estart
hel
count: 1
6
hel
count: 1
6
hel
count: 1
6
hel
count: 1
6
hel
....
何かアドバイスは本当にいただければ幸いです!
ありがとうございます 目的は真のステートメントの数を数えることです。これが私が毎回1ずつ増やす理由です。
「is_legitimate_route」は何をしていますか? [mcve]を入力してください。 –
これは実際のコードですか?なぜなら、この '1'はそれぞれの' hel'の後にどこに印刷されているのかわからないからです。 – AKS
前の点に加えて、なぜ7が印刷されていないのですか? –