-
Notifications
You must be signed in to change notification settings - Fork 3
/
lists_11-14-2019.py
43 lines (31 loc) · 1.52 KB
/
lists_11-14-2019.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 1.
# Write a function that takes a list of numbers (for example, a = [5, 10, 15, 20, 25])
# and makes a new list of only the first and last elements of the given list
# code here
# 2.
# Take a list, say for example this one:
# a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
# and write a function that returns a new list with all the elements of
# the list that are less than 5. Try writing it as a one liner(list comprehension)
# code here
# 3.
# Take two lists, say for example these two:
# a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
# b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
# and write a program that returns a list that contains only the elements that are
# common between the lists (without duplicates).
# Make sure your program works on two lists of different sizes.
# also try to if you can make it a one liner using list comprehension
# 4.
# Let’s say I give you a list saved in a variable:
# a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100].
# Write a function one that takes this list a and makes a new list that
# has only the even elements of this list in it. use list comprehension
# 5.
# write a function that takes in a list of numbers and returns a new list without
# the duplicates, i.e given [34, 4, 5, 34, 45, 4, 5, 45] returns [34, 4, 5, 45]
# 6.
# Write a function that takes an array, starting index and index. and returns a list
# with items from start_index to end index from the given list, end_index inclusive
# e.g given [2, 7, 23, 45, 12, 67] start_index = 1, end_index = 5
# return [7, 23, 45, 12, 67]