Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
list - 2 questions:
#1
question number one:
The function gets a list of strings of even length. The function returns a string that contains the list members in the even positions, separated by a comma and a space, as well as the last member with the caption and in front of it.
my try is:
def format_list(my_list):
    """
    This function returns the words in the list which is in the even side.
    :param my_list: The list of the project.
    :type my_list: str, int, float
    :rtype: str, int, float
    :return: The result of the list on the even only.
    """
    my_list = []
    if len(my_list) % 2 == 0:
        return my_list[0::2]

new_list = format_list(my_list=["hydrogen", "helium", "lithium", "beryllium", "boron", "magnesium"])
print(new_list)
output is:
[]

I dont get it, no matter what I try, I wont get anything other than the []...
I dont need a solution, What I need is a tip, what to change here ( only one thing, ill try to understand alone the rest ).

EDIT: I know this question doesnt include the and thingy, but I first want to see that im getting something instead of [] at output. when ill get it, ill add it with join function, but first of all, i want to fix this code so it will work.
________________________________________________________________________________________________________

second question:
Write a function called shift_left. The function receives a list of length 3 and returns a new list moved one step to the left.
Function definition === def shift_left (my_list):
Examples of running the shift_left function
>>> shift_left ([0, 1, 2])
[1, 2, 0]
>>> shift_left (['monkey', 2.0, 1])
[2.0, 1, 'monkey']

my try:
def shift_left(my_list):
    """
    This function moves the list with 3 numbers one step to the left.
    If it was 0 1 2, then it will be 1, 2, 0.
    :param my_list: The numbers of the list I will choose.
    :type my_list: str, int, float
    :rtype
    :return: the result of the list with one step left.
    """
    my_list = [param1, param2, param3]
    new_list = my_list[::-1]
well, to be honest ,at this one, I dont have the other tries I had, I had in here 3 solutions, only 1 worked, but it wasnt according to how it should be... the one that worked If I wrote a string inside the my_list at the definition at the end, it would have worked ( i cant have it since it was before hours ago ). the other two are long long gone... this one I just left it like that and went on to the next question ( which is the first question up there, I did it opposite here, but it doesnt matter ).
I managed to find a solution for this one online, but it concluded 2 definitions, I dont think it should be part of the solution... if there is any other thing, ill be happy for a tip also, only a small tip so I can continiue.
_____________________________________________________________________________________________________

now, I know im not using BBCODE and i was told twice in my threads not to post without it, but seriously, the link https://python-forum.io/misc.php?action=help&hid=25 doesnt say at all how to use it... all I understood from there, that i need to put python between my code and thats it... the explanation there is not really understandable, i cant post in bbcode because of it... all i can do is the code thingy... if its not allowed, then i guess ill be stuck ( cus you must use bbcode as i understood ).
Reply


Messages In This Thread
list - 2 questions: - by ben1122 - Jul-31-2021, 11:33 AM
RE: list - 2 questions: - by ndc85430 - Jul-31-2021, 11:36 AM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 11:41 AM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 11:43 AM
RE: list - 2 questions: - by ndc85430 - Jul-31-2021, 11:46 AM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 11:48 AM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 11:44 AM
RE: list - 2 questions: - by ndc85430 - Jul-31-2021, 11:45 AM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 11:47 AM
RE: list - 2 questions: - by ndc85430 - Jul-31-2021, 12:05 PM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 12:08 PM
RE: list - 2 questions: - by ndc85430 - Jul-31-2021, 12:10 PM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 12:16 PM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 12:17 PM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 12:17 PM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 12:19 PM
RE: list - 2 questions: - by ndc85430 - Jul-31-2021, 12:23 PM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 12:31 PM
RE: list - 2 questions: - by ndc85430 - Jul-31-2021, 12:37 PM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 12:39 PM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 12:37 PM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 12:40 PM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 12:49 PM
RE: list - 2 questions: - by ndc85430 - Jul-31-2021, 12:50 PM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 12:53 PM
RE: list - 2 questions: - by ndc85430 - Jul-31-2021, 01:00 PM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 01:03 PM
RE: list - 2 questions: - by ndc85430 - Jul-31-2021, 01:24 PM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 01:32 PM
RE: list - 2 questions: - by ndc85430 - Jul-31-2021, 01:36 PM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 02:03 PM
RE: list - 2 questions: - by ndc85430 - Jul-31-2021, 02:05 PM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 02:24 PM
RE: list - 2 questions: - by deanhystad - Jul-31-2021, 03:11 PM
RE: list - 2 questions: - by ben1122 - Jul-31-2021, 03:31 PM
RE: list - 2 questions: - by deanhystad - Jul-31-2021, 05:06 PM
RE: list - 2 questions: - by Pedroski55 - Jul-31-2021, 11:18 PM
RE: list - 2 questions: - by Pedroski55 - Jul-31-2021, 11:48 PM
RE: list - 2 questions: - by Pedroski55 - Aug-01-2021, 03:06 AM
RE: list - 2 questions: - by snippsat - Aug-01-2021, 04:27 PM
RE: list - 2 questions: - by naughtyCat - Aug-18-2021, 05:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Discord bot that asks questions and based on response answers or asks more questions absinthium 1 48,908 Nov-25-2017, 06:21 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020