Andi Saliaj

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

1

np.prod function from the numpy library is used to calculate the product of all elements in
the list, making the code helpful and easy to understand

max function is used to find the largest number, and the min function is used to find the
smallest number. The default=None is used to handle the case when the list is empty. This
makes the code shorter and more concise

set(original_list), which automatically removes duplicates. Then, it's


converted back to a list using list() to get the final result. This approach is
concise and straightforward.
4
In this version, a list comprehension is used to create the long_words list in a single line,
making the code shorter and more straightforward.

extract_usernames function takes a list of email addresses and uses a list comprehension
to split each email at the '@' symbol and extract the username part (the first element after
splitting).

Adjust the email_addresses list according to your input, and the usernames list will contain
the extracted usernames.
6

get_random_elements() that returns a tuple of randomly chosen elements from the three
lists. The selected elements are then printed.

program achieves the same result but with a more concise printing statement. It still
unpacks the tuple into the variables var1, var2, and var3.

str(my_tuple) directly converts the entire tuple to a string. The resulting string will include
parentheses and commas, representing the tuple structure. The output will be:
9

We can use and my_tuple. You can replace element_to_check with any value you want to check for
existence in the tuple.

10

find_duplicates iterates through the tuple and keeps track of seen items. If an item is
encountered again, it's added to the duplicates set. The resulting set contains the
repeated items.

11

using random.shuffle(). Then, it splits the shuffled deck into 4 lists of roughly equal size.
The resulting lists represent the shuffled deck distributed among 4 players or piles.

12

zip(keys, values) pairs the elements from the keys and values lists, and dict() then
converts those pairs into a dictionary. The resulting dictionary will have keys from the 'keys'
list and corresponding values from the 'values' list.

13

each successive key is used to access the nested dictionaries until the 'history'
key is reached, and its associated value (80) is printed.
14

You might also like