Python Forum
How do i make a new lists out of an list - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How do i make a new lists out of an list (/thread-30624.html)



How do i make a new lists out of an list - ozezn1 - Oct-28-2020

I'm trying to make my first app and was wondering how do I make a list out of a list. Following some tutorials on udemy .

list_body = ["head","arms","legs"]
list_head = ["eyes","nose","mouth"]
list_eyes = ["color","shape"]
The concept is as this:
Body is my main list followed up by a -> new list Head, which has its lists -> Eyes

I understand it so far: I run a for loop through all body parts then I attach all head data to head but I'm not sure how to do this.
print(muscle_group)
empty_muscle_group = []
for number_list in muscle_group:
    empty_muscle_group.append(number_list)
print(empty_muscle_group)
this is what iv come across so far. I will allow inputs to be done to add new data but for now, I want to understand the basics


RE: How do i make a new lists out of an list - Gribouillis - Oct-28-2020

Here are various ways to copy a list
>>> body =  ["head","arms","legs"]
>>> another = list(body)
>>> another
['head', 'arms', 'legs']
>>> body.append('feet')
>>> body
['head', 'arms', 'legs', 'feet']
>>> another
['head', 'arms', 'legs']
>>> one_more = [x for x in body]
>>> one_more
['head', 'arms', 'legs', 'feet']
>>> again = body[:]
>>> again
['head', 'arms', 'legs', 'feet']
>>> import copy
>>> yet_another = copy.copy(body)