03 Lists Basics Lab
03 Lists Basics Lab
Please, submit your source code solutions for the described problems to the Judge System.
1. Strange Zoo
You are at the zoo, and the meerkats look strange.
You will receive 3 strings on separate lines, representing the tail, the body, and the head of an animal in that order.
Your task is to re-arrange the elements in a list so that the animal looks normal again:
On the first position is the head;
On the second position is the body;
On the last one is the tail.
Example
Input Output
my tail ['my head is on the wrong end!', 'my body
my body seems on place seems on place', 'my tail']
my head is on the wrong end!
tail ['head', 'body', 'tail']
body
head
T ['H', 'B', 'T']
B
H
Hints
We start by reading the three parts of the body:
2. Courses
On the first line, you will receive a single number n. On the following n lines, you will receive names of courses. You
should create a list of courses and print it.
Example
Input Output
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Hints
We read the number n from the console, and we create an empty list:
Then, we create a loop that reads each course and adds it to the list:
3. List Statistics
On the first line, you will receive a number n. On the following n lines, you will receive integers. You should create
and print two lists:
One with all the positive (including 0) numbers
One with all the negative numbers
Finally, print the following message:
"Count of positives: {count_positives}
Sum of negatives: {sum_of_negatives}"
Example
Input Output
5 [10, 3, 2]
10 [-15, -4]
3 Count of positives: 3
2 Sum of negatives: -19
-15
-4
6 [11, 2, 35, 599, 31, 20]
11 []
2 Count of positives: 6
35 Sum of negatives: 0
599
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Hints
We start by reading the number n:
Then, we create a loop that reads the current number and checks if it is positive or not:
To get the count of the positives, we can use the len function.
To get the sum of the negatives, we can use the sum function.
4. Search
On the first line, you will receive a number n. On the second line, you will receive a word. On the following n lines,
you will be given some strings. You should add them to a list and print them. After that, you should filter out only
the strings that include the given word and print that list too.
Example
Input Output
3 ["I study at SoftUni", "I walk to work", "I
SoftUni learn Python at SoftUni"]
I study at SoftUni ["I study at SoftUni", "I learn Python at
I walk to work SoftUni"]
I learn Python at SoftUni
4 ["I love tomatoes", "I can eat tomatoes
tomatoes forever", "I don't like apples", "Yesterday
I love tomatoes I ate two tomatoes"]
I can eat tomatoes forever ["I love tomatoes", "I can eat tomatoes
I don't like apples forever", "Yesterday I ate two tomatoes"]
Yesterday I ate two tomatoes
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
We create a loop that adds all the strings to our list. After that, we print it:
Finally, we create another loop to remove the strings we do not need by iterating through the strings reversed (so
we don't skip elements when removing) and print the list again:
5. Numbers Filter
On the first line, you will receive a single number n. On the following n lines, you will receive integers. After that, you
will be given one of the following commands:
even
odd
negative
positive
Filter all the numbers that fit in the category (0 counts as a positive and even). Finally, print the result.
Example
Input Output
5 [-2, 18,
33 998]
19
-2
18
998
even
3 [-4]
111
-4
0
negativ
e
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
We create a loop that reads all the numbers and adds them to the list:
Then, we read the command and check for all the cases:
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.