Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List Comprehensions
#3
Quote:A) Though both yield the same result, is one way faster than the other?
LC is faster.

Quote:B) In the 'real world' of using Python - is it frowned upon to build lists not using the list comprehension feature (assuming execution time is the same)?
LC is used everywhere in Python.
There also a functional program way,but LC is looked upon as more pythonic.
Eg:
>>> lst = ['1', '500', '999']
>>> [int(i) for i in lst]
[1, 500, 999]

# Functional program way
>>> list(map(int, lst))
[1, 500, 999]
Quote:At first glance, this seems like a Personal Preference vs Actual Performance battle.
Not so much a Performance thing,LC has become a natural part of the Python language.
Reply


Messages In This Thread
List Comprehensions - by ATXpython - Oct-01-2016, 06:07 PM
RE: List Comprehensions - by ichabod801 - Oct-01-2016, 06:30 PM
RE: List Comprehensions - by snippsat - Oct-01-2016, 06:38 PM
RE: List Comprehensions - by Ofnuts - Oct-01-2016, 09:20 PM
RE: List Comprehensions - by Larz60+ - Oct-01-2016, 09:44 PM
RE: List Comprehensions - by Skaperen - Oct-02-2016, 01:02 AM
RE: List Comprehensions - by metulburr - Oct-02-2016, 01:09 AM
RE: List Comprehensions - by snippsat - Oct-02-2016, 08:56 AM
RE: List Comprehensions - by Yoriz - Oct-02-2016, 11:39 AM
RE: List Comprehensions - by Larz60+ - Oct-02-2016, 11:59 AM
RE: List Comprehensions - by Yoriz - Oct-02-2016, 12:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  abusing comprehensions for one line loops Skaperen 6 2,684 Dec-16-2019, 11:22 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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