Skip to content

Instantly share code, notes, and snippets.

@mvallebr
Created February 9, 2018 00:30
Show Gist options
  • Select an option

  • Save mvallebr/4b3b3aa12131f002672e6b27fb7fae7e to your computer and use it in GitHub Desktop.

Select an option

Save mvallebr/4b3b3aa12131f002672e6b27fb7fae7e to your computer and use it in GitHub Desktop.
a = [123, 234]
def a1():
yield 123
yield 234
b = {"nome": 123, "nome2": "matecki"}
print (b["nome"])
print (b["nome2"])
# Exemplo de list comprehension
a = ["segunda", "terca", "quarta", "quinta", "sexta", "sabado", "domingo"]
b = []
for e in a:
if len(e) < 6:
b.append(e)
# b = ["terca", "sexta"]
print ("b = ", str(b))
b = [e for e in a if len(e) < 6]
# Exemplo dict comprehension
c = {}
for e in a:
c[e] = len(a)
# c = {"segunda": 7, "terca": 5, "quarta": 6, "quinta": 6, "sexta": 5, "sabado": 6, "domingo": 7}
print ("c = ", str(c))
c = {e: len(e) for e in a}
c2 = {e: len(e) for e in a if len(e) < 6}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment