Python Forum
How do i make a new lists out of an list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do i make a new lists out of an list
#1
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
Reply
#2
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,341 May-22-2023, 10:39 PM
Last Post: ICanIBB
  List all possibilities of a nested-list by flattened lists sparkt 1 921 Feb-23-2023, 02:21 PM
Last Post: sparkt
  user input values into list of lists tauros73 3 1,075 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  help me to make my password list in python >>> Oktay34riza 0 583 Dec-23-2022, 12:38 PM
Last Post: Oktay34riza
  returning a List of Lists nafshar 3 1,069 Oct-28-2022, 06:28 PM
Last Post: deanhystad
  Creating list of lists, with objects from lists sgrinderud 7 1,649 Oct-01-2022, 07:15 PM
Last Post: Skaperen
  How to efficiently average same entries of lists in a list xquad 5 2,124 Dec-17-2021, 04:44 PM
Last Post: xquad
  sorting a list of lists by an element leapcfm 3 1,877 Sep-10-2021, 03:33 PM
Last Post: leapcfm
  Make Groups with the List Elements quest 2 1,977 Jul-11-2021, 09:58 AM
Last Post: perfringo
  behavior list of lists roym 5 2,098 Jul-04-2021, 04:43 PM
Last Post: roym

Forum Jump:

User Panel Messages

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