Contact: aviboots(AT)netvision.net.il
40,849 questions
53,254 answers
573 users
lst = [34, 78, 90, 'python', 'java', 'c++'] N = 4 new_list = lst[:N] print(new_list) ''' run: [34, 78, 90, 'python'] '''
lst = [34, 78, 90, 'python', 'java', 'c++'] N = 4 new_list = [] for index in range(0, N): new_list.append(lst[index]) print(new_list) ''' run: [34, 78, 90, 'python'] '''
lst = [34, 78, 90, 'python', 'java', 'c++'] N = 4 new_list = [item for index, item in enumerate(lst) if index < N] print(new_list) ''' run: [34, 78, 90, 'python'] '''