-2

I have an array of N elements.

x = [ 1  , 2, ....... , N]

How can i split it into 8:2 arrays?

The first array should have 80% elements and the second rest.

hpaulj
  • 221,503
  • 14
  • 230
  • 353
jejjejd
  • 721
  • 1
  • 8
  • 18

2 Answers2

2

In order to calculate the ratio, you need to first find the length of the list x:

len(x)

To find 80% of the list, multiply the length by 80%:

len(x)*.8

This will return a float. You need to convert it into an int for list slicing:

int(len(x)*.8)

Next you need to slice the list. Here is a good resource on the basics of list slicing. It will look something like this:

x[:int(len(x)*.8)]

See if you can figure out how to make the second list for the remaining 20%.

scienceyeaux
  • 65
  • 1
  • 6
2

first enter any list x=[1,2,3....n] then do this function y=(Len(x) * 4) // 5 then split it to 2 lists a=x[0:y] b=x[-(Len(x)-y):]

Shehab El-din
  • 31
  • 1
  • 3