Quick List and Tuples Examples Python
Quick List and Tuples Examples Python
Quick List and Tuples Examples Python
# random
# import random
# num = [1,1,5,5,9,9,7,55,55,456,456,123]
# winnerChoice = random.choice(num) #random
# winnerChoices = random.choices(num,k=3) #3 random
# winnerSample = random.sample(num,k=3) # 3 random without duplicate
# print(winnerChoice)
# print(winnerChoices)
# print(winnerSample)
# # looping in reverse
# for i in reversed(my_string):
# print(i)
# # slice list
# my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# midpoint = len(my_list) // 2
# start_index = 3
# end_index = 7
# first_half = my_list[:midpoint]
# second_half = my_list[midpoint:]
# slice_from_StartPoint = my_list[start_index:]
# slice_from_EndPoint = my_list[:end_index]
# my_string = "1/2/3/4/5/6/7/8/9/10"
# word_List = my_string.split("/")
# print(word_List)
# # list ends
# a = [5,10,15,20,25]
# end = [a[0], a[len(a)-1]]
# print(end)
# arr = [1,1,2,3,4,4,5,6,7,7,8,9,9,10,10]
# print(listRemoverLoops(arr))
# # remove duplicates using sets
# removeSet = set(arr)
# print(removeSet)
# # Truples Example
# # Trples are immutable (cannot be changed)
# # they fast asf too while having data integrity
# my_tuple = (1, 2, 3, 'a', 'b', 'c')
# print(my_tuple[0]) # Output: 1
# print(my_tuple[3]) # Output: 'a'
# print(my_tuple.count('a')) # Output: 1
# print(my_tuple.index('b')) # Output: 4
# my_packed_tuple = 1, 2, 3 # Packing
# x, y, z = my_packed_tuple # Unpacking
# print(len(my_tuple)) # Output: 6