-2

i need help. Please How can I divide a list in Python, into two equal parts and delete one part. Then assign one part to a new variable.

example

list = ['name', 'can', 'she', 'men', 'them', 3, 4, 5, 6, 7]

How then can I delete half part of this list and assign half to a new variable

new_list = ['name', 'can', 'she', 'men', 'them']
Mark Dickinson
  • 29,088
  • 9
  • 83
  • 120
Drunk Codes
  • 39
  • 2
  • 7
  • 1
    You shouldn't call your variables `list`, or any other built-in type or function. – sjw May 21 '18 at 15:04
  • if order doesn't matter, new_list = list(set(dup_list)) will work – Foon May 21 '18 at 18:33
  • Your edit completely changes the question and invalidates the existing answer. I've rolled back the change. I'd suggest asking a new question instead. – Mark Dickinson May 21 '18 at 19:06

1 Answers1

6

You just need a slice:

new_list = list[:len(list)//2]
chepner
  • 497,756
  • 71
  • 530
  • 681