Στις 26/10/2013 5:10 μμ, ο/η Nick the Gr33k έγραψε:
[QUOTE=turvey]Say your data is like the following: data = [('alice', 1), ('alice', 2), ('bob', 5), ('bob', 10), ('carrie', 3)]Where the first entry is your user and the second entry is a timestamp. Your data is structured basically like this, except I stripped the irrelevant details. [CODE] user_to_timestamps = {} # Gather all your users together. for user,timestamp in data: if user not in user_to_timestamp: user_to_timestamp[user] = [] user_to_timestamp[user].append(timestamp) # You now have a data structure like this # {'alice': [1, 2], 'bob': [5, 10], 'carrie': [3]} for user, timestamps in user_to_timestamps.iteritems(): print user for timestamp in timestamps: print "<select>%s</select>" % timestamp [/CODE] There. That's how you would do it. It shouldn't be much work to get your code into that form.[/QUOTE] I'am sorry but i still cannot transform my code: [CODE] try: cur.execute( '''SELECT host, city, useros, browser, ref, hits, lastvisit FROM visitors WHERE counterID = (SELECT ID FROM counters WHERE url = %s) ORDER BY lastvisit DESC''', page ) data = cur.fetchall() for row in data: (host, city, useros, browser, ref, hits, lastvisit) = row lastvisit = lastvisit.strftime('%A %e %b, %H:%M') print( "<tr>" ) for item in (host, city, useros, browser, ref, hits, lastvisit): print( "<td><center><b><font color=white> %s </td>" % item ) except pymysql.ProgrammingError as e: print( repr(e) ) [/CODE] to the solution you presented :( I just dont know how to write it.
Can someone write this properly? i tried but cannot make it work. -- What is now proved was at first only imagined! & WebHost <http://superhost.gr> -- https://mail.python.org/mailman/listinfo/python-list
