Find duplicates in a list of tuples You are given information about users of your website. The information
  includes username, a phone number and/or an email. Write a program
  that takes in a list of tuples where each tuple represents information
  for a particular user and returns a list of lists where each sublist
  contains the indices of tuples containing information about the same
  person. For example:
  
  Input:

[("MLGuy42", "andrew@gmail.com", "123-4567"),
("CS229DungeonMaster", "123-4567", "ml@stanford.edu"),
("Doomguy", "john@oculus.com", "carmack@gmail.com"),
("andrew26", "andrew@gmail.com", "mlguy@gmail.com")]

  
  Output:

[[0, 1, 3], [2]]

  
  Since "MLGuy42", "CS229DungeonMaster" and "andrew26" are all the same
  person.
  
  Each sublist in the output should be sorted and the outer list should
  be sorted by the first element in the sublist.


Below is the code snippet that I did for this problem. It seems to work fine, but I'm wondering if there is a better/optimized solution.

def find_duplicates(user_info):
    results = list()
    seen = dict()
    for i, user in enumerate(user_info):
        first_seen = True
        key_info = None
        for info in user:
            if info in seen:
                first_seen = False
                key_info = info
                break
        if first_seen:
            results.append([i])
            pos = len(results) - 1
        else:
            index = seen[key_info]
            results[index].append(i)
            pos = index
        for info in user:
            seen[info] = pos
    return results
There is a way to increase readability.  A for-else statement can be used to replace flags that are only set on break.  Click here to learn more.  The else clause is only called if the loop completes without break being called.

def find_duplicates(user_info):
    results = list()
    seen = dict()
    for i, user in enumerate(user_info):
        for info in user:
            if info in seen:
                index = seen[info]
                results[index].append(i)
                pos = index
                break
        else:
            results.append([i])
            pos = len(results) - 1
        for info in user:
            seen[info] = pos
    return results


How I tested speeds

Your code, as it currently stands, will work exactly the same with integers. So, I just randomly generated large data sets this way (and played along with MAXVALUE and range a bit.

from random import randrange
from timeit import timeit
MAXVALUE = 1000

for a in range(5): #I wanted to make sure I checked 5 to make sure I don't get a outlier data set that effects my ability to use timeit reasonably.
    user_info = [[randrange(MAXVALUE) for i in range(3)] for _ in range(1000)]
    print(timeit(lambda: find_duplicates(user_info), number=10000))


Credit for improving code: Maarten Fabré