fork(1) download
  1. def nao_comuns(a,b):
  2. a_b = a+b # juntar as duas para percorrer todos os elementos
  3. nao_comuns = []
  4. for ele in a_b:
  5. if ele not in a or ele not in b: # nao existe numa delas
  6. nao_comuns.append(ele)
  7. return nao_comuns
  8.  
  9. a = range(10) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  10. b = range(0,20,2) # [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
  11. print nao_comuns(a,b) # [1, 3, 5, 7, 9, 10, 12, 14, 16, 18]
Success #stdin #stdout 0s 23352KB
stdin
Standard input is empty
stdout
[1, 3, 5, 7, 9, 10, 12, 14, 16, 18]