O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Code 1.pptx

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Carregando em…3
×

Confira estes a seguir

1 de 7 Anúncio

Mais Conteúdo rRelacionado

Mais recentes (20)

Anúncio

Code 1.pptx

  1. 1. Code 1 alphabet = "abcdefghijklmnopqrstuvwxyz" test_dups = ["zzz","dog","bookkeeper","subdermatoglyphic","subdermatoglyphics"] test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the lazy dog"] def histogram(s): d = dict() for c in s: if c not in d: d[c] = 1 else: d[c] += 1 return d def has_duplicates(s):
  2. 2. Code 2 • for d in histogram(s).values(): #implementing the histogram • if d > 1: #checking for duplicates • return True • else: • return False • • for letts in test_dups: • if has_duplicates(letts): • print(letts, "has duplicates.") • else: • print(letts, "has no duplicates.")
  3. 3. Output: • zzz has duplicates. • dog has no duplicates. • bookkeeper has no duplicates. • subdermatoglyphic has no duplicates. • subdermatoglyphics has duplicates.
  4. 4. Code 3 • alphabet = "abcdefghijklmnopqrstuvwxyz" • • test_dups = ["zzz","dog","bookkeeper","subdermatoglyphic","subdermatoglyphics"] • • test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the lazy dog"] • • • def histogram(s): • d = dict() • for c in s: • if c not in d: • d[c] = 1 • else: • d[c] += 1 • return d
  5. 5. Code4 • def missing_letters(s): • his = histogram(s) • lis = [] • • for c in alphabet: • if c not in his: • lis.append(c) • return ''.join(lis) • • for s in test_miss: • miss_lettss = missing_letters(s) • if len(miss_lettss): • print(s, "is missing.") • • else: • print(s, "has all letters.")
  6. 6. Output: • zzz is missing. • subdermatoglyphic is missing. • the quick brown fox jumps over the lazy dog has all letters.
  7. 7. Thank You

×