Skip to content

Commit 5f246b6

Browse files
authored
Merge pull request #83 from lironmiz/unit6-Ex6.2.3
Create unit6_ex6.2.3.py
2 parents 9ecc229 + f50ec43 commit 5f246b6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

unit6_ex6.2.3.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# exersice 6.2.3 from unit 6
2+
'''
3+
Write a function called format_list defined as follows:
4+
5+
def format_list(my_list):
6+
The function receives a list of strings of even length. The function returns a string containing the members of the list in the even positions, separated by a comma and a space, and also the last member with the inscription and before it.
7+
8+
An example of running the format_list function
9+
>>> my_list = ["hydrogen", "helium", "lithium", "beryllium", "boron", "magnesium"]
10+
>>> format_list(my_list)
11+
hydrogen, lithium, boron, and magnesium
12+
13+
Guidelines
14+
Do not use loops.
15+
'''
16+
def format_list(my_list):
17+
formatted_list = ', '.join(my_list[::2])
18+
return f"{formatted_list} and {my_list[-1]}"
19+
20+
21+
def main():
22+
my_list = ["hydrogen", "helium", "lithium", "beryllium", "boron", "magnesium"]
23+
formatted_list = format_list(my_list)
24+
print(formatted_list)
25+
26+
if __name__ == "__main__":
27+
main()
28+

0 commit comments

Comments
 (0)