def is_symmetric(l):
    # TODO

assert(is_symmetric([1]) == True)
assert(is_symmetric([]) == True)
assert(is_symmetric([1, 2, 3, 1]) == False)
assert(is_symmetric([1, "foo", "bar", "foo", 1]) == True)
assert(is_symmetric("abcba") == True)

"""
Explanation: Laboratory 02
Requirements
For the second part of the exercises you will need the wikipedia package. On Windows machines, use the following command in the Anaconda Prompt (Start --&gt; Anaconda --&gt; Anaconda Prompt):
conda install -c conda-forge wikipedia

This command should work with other Anaconda environments (OSX, Linux).
If you are using virtualenv directly instead of Anaconda, the following command installs it in your virtualenv:
pip install wikipedia

or
sudo pip install wikipedia

installs it system-wide.
You are encouraged to reuse functions that you defined in earlier exercises.
1.1 Define a function that takes a sequence as its input and returns whether the sequence is symmetric. A sequence is symmetric if it is equal to its reverse.
End of explanation
"""


def k_largest(l, k=1):
    pass
    

l = [-1, 0, 3, 2]

assert(k_largest(l) == [3])
assert(k_largest(l, 2) == [2, 3] or k_largest(l, 2))

"""
Explanation: 1.2 Define a function that takes a sequence and an integer $k$ as its input and returns the $k$ largest element. Do not use the built-in max function. Do not change the original sequence. If $k$ is not specified return one element in a list.
End of explanation
"""


def transpose(M):
    # TODO

m1 = [[1, 2, 3], [4, 5, 6]]
m2 = [[1, 4], [2, 5], [3, 6]]

assert(transpose(m1) == m2)
assert(transpose(transpose(m1)) == m1)

"""
Explanation: *1.3 Add an optional key argument that works analogously to the built-in sorted's key argument.
Define a function that takes a matrix as an input represented as a list of lists (you can assume that the input is a valid matrix). Return its transpose without changing the original matrix.
End of explanation
"""


def char_freq(s):
    # TODO
    
assert(char_freq("aba") == {"a": 2, "b": 1})

"""
Explanation: 2.1 Define a function that takes a string as its input and return a dictionary with the character frequencies.
End of explanation
"""


def char_freq_with_skip(s, skip_symbols=None):
    # TODO
    
assert(char_freq_with_skip("ab.abc?", skip_symbols=".?") == {"a": 2, "b": 2, "c": 1})

"""
Explanation: 2.2 Add an optional skip_symbols to the char_freq function. skip_symbols is the set of symbols that should be excluded from the frequence dictionary. If this argument is not specified, the function should include every symbol.
End of explanation
"""


def word_freq(s):
    # TODO
    
s = "the green tea and the black tea"

assert(word_freq(s) == {"the": 2, "tea": 2, "green": 1, "black": 1, "and": 1})

"""
Explanation: 2.2 Define a function that computes word frequencies in a text.
End of explanation
"""


def count_upper_case(s):
    # TODO
    
assert(count_upper_case("A") == 1)
assert(count_upper_case("abA bcCa") == 2)

"""
Explanation: 2.3 Define a function that count the uppercase letters in a string.
End of explanation
"""


def anagram(s1, s2):
    # TODO

assert(anagram("abc", "bac") == True)
assert(anagram("aabb", "abab") == True)
assert(anagram("abab", "aaab") == False)

"""
Explanation: 2.4 Define a function that takes two strings and decides whether they are anagrams. A string is an anagram of another string if its letters can be rearranged so that it equals the other string.
For example:
abc -- bac
aabb -- abab
Counter examples:
abc -- aabc
abab -- aaab
End of explanation
"""


def sentence_splitter(s):
    # TODO
        
assert(sentence_splitter("A.b. acd.") == ['A.b', 'acd'])
assert(sentence_splitter("A. b. acd.") == ['A', 'b', 'acd'])

"""
Explanation: 2.5. Define a sentence splitter function that takes a string and splits it into a list of sentences. Sentences end with . and the new sentence must start with a whitespace (str.isspace) or be the end of the string. See the examples below.
End of explanation
"""


import wikipedia

results = wikipedia.search("Budapest")
results

"""
Explanation: Wikipedia module
The following exercises use the wikipedia package. The basic usage is illustrated below.
The documentation is available here.
Searching for pages:
End of explanation
"""


article = wikipedia.page("Budapest")

article.summary[:100]

"""
Explanation: Downloading an article:
End of explanation
"""


type(article.content), len(article.content)

"""
Explanation: The content attribute contains the full text:
End of explanation
"""


wikipedia.set_lang("fr")

wikipedia.search("Budapest")

fr_article = wikipedia.page("Budapest")
fr_article.summary[:100]

"""
Explanation: By default the module downloads the English Wikipedia. The language can be changed the following way:
End of explanation
"""


