2 + 2
name = "world"
print("hello " + name)
list(range(12))
[n * 2 for n in range(12)]
[n for n in range(12) if n > 5]
for i in range(4):
print(i)
for word1 in ["abe", "sø", "citron"]:
for word2 in ["kat", "uhyre", "græs"]:
print(word1 + word2)
len(['a', 'b', 'c', 'd'])
len('hej')
for word1 in ["abe", "sø", "citron"]:
for word2 in ["kat", "uhyre", "græs"]:
if len(word1 + word2) > 6:
print(word1 + word2)
data = {
"a": [11,22,33],
"b": {
"c": 456
}
}
print(data)
import json
print(json.dumps(data))
json.loads('{"d":[7,8],"e":"f"}')
data["a"]
data["a"][0]
data["a"][2]
data.get("a", "hej")
data.get("x", "hej")
list(data.keys())
list(data.values())
import requests
fortunes = requests.get('https://raw.githubusercontent.com/JKirchartz/fortune/master/jung').text
print(fortunes[0:500])
"hej med dig".split(" ")
import random
random.choice([4,5,6,7])
print(random.choice(fortunes.split('%\n')))
words = fortunes.split(' ')
words[0:10]
from collections import Counter
Counter(words).most_common(10)