Posts

Showing posts from April, 2021
USEFUL PYTHON TIPS AND TRICKS 👀 I'd like to share this today!!!  # Swap two variables with one line of code. Shorten your code a = 1 b =2 a, b = b, a # Duplicate strings without looping fruit_names = "Banana", "Mango" print (fruit_names * 4) # Reverse a string my_words = "The Quick Brown Fox" reverse_words = my_words[::-1] print(reverse_words) # Compress a list of strings into one string my_words = ["This", "is", "a", "Test"] combine_all = " ".join(my_words) print(combine_all) # You can also compare or evaluate in a line of code x = 100 res = 0 < x < 1000 > 50 print(res) # Find the most frequest element in a list test_list = [4, 3, 2, 3, 2, 4, 3, 6, 9, 41, 2, 3, 4] most_frequent = max(set(test_list), key = test_list.count) print(most_frequent) # Unpack list to separate variables (or assign list to separate varabiels) arr_list = [1,2,3] a,b,c = arr_list print(a,b,c) # One-liner if-else statemen...