Skip to main content
Shorten.
Source Link
Mateen Ulhaq
  • 28.1k
  • 22
  • 122
  • 157

Pythonic way to return Make a new list ofcontaining every nthNth item in a largerthe original list

Say we have a list of numbersintegers from 0 to 1000. Is there a pythonic/efficient way to produce:

[0, 1, 2, 3, ..., 997, 998, 999]

How do I get a new list ofcontaining the first and every subsequent 10th item, i.e. [0, 10, 20, 30, ... ]?

[0, 10, 20, 30, ..., 990]

Yes, I can do this using a for loop, but I'm wondering if there is there a neater way to do this, perhaps even in one line of code?

Pythonic way to return list of every nth item in a larger list

Say we have a list of numbers from 0 to 1000. Is there a pythonic/efficient way to produce a list of the first and every subsequent 10th item, i.e. [0, 10, 20, 30, ... ]?

Yes, I can do this using a for loop, but I'm wondering if there is a neater way to do this, perhaps even in one line?

Make a new list containing every Nth item in the original list

Say we have a list of integers from 0 to 1000:

[0, 1, 2, 3, ..., 997, 998, 999]

How do I get a new list containing the first and every subsequent 10th item?

[0, 10, 20, 30, ..., 990]

I can do this using a for loop, but is there a neater way, perhaps even in one line of code?

added 5 characters in body; edited title
Source Link
nbro
  • 16.1k
  • 35
  • 122
  • 220

Pythonic way to return list of every n'thnth item in a larger list

Say we have a list of numbers from zero0 to 1000. Is there a pythonic/efficient way to produce a list of the first and every subsequent 10th item? ie. [0, 10, 20, 30 .i.e.] [0, 10, 20, 30, ... ]?

Yes, I can do this using a for loop, but I'm wondering if there is a neater way to do this, perhaps even in one line?

Pythonic way to return list of every n'th item in a larger list

Say we have a list of numbers from zero to 1000. Is there a pythonic/efficient way to produce a list of the first and every subsequent 10th item? ie. [0, 10, 20, 30 ...]

Yes I can do this using a for loop but I'm wondering if there is a neater way to do this, perhaps even in one line?

Pythonic way to return list of every nth item in a larger list

Say we have a list of numbers from 0 to 1000. Is there a pythonic/efficient way to produce a list of the first and every subsequent 10th item, i.e. [0, 10, 20, 30, ... ]?

Yes, I can do this using a for loop, but I'm wondering if there is a neater way to do this, perhaps even in one line?

edited tags
Link
SilentGhost
  • 322.7k
  • 67
  • 312
  • 294
edited tags
Link
SilentGhost
  • 322.7k
  • 67
  • 312
  • 294
Loading
Source Link
p.brown
  • 2.6k
  • 2
  • 17
  • 8
Loading