Python Forum
[split] question about list comprehension
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] question about list comprehension
#4
(Jan-12-2020, 03:43 PM)Armin Wrote: Thanks for your reply what bothers me most about this code is line 7 this part y = [i for i in input ('give me a number:') i know this is list comprehensions but i don't understand it how this line of code number 7 works ??

[i for i in input('give me a number: ').split(',')]
number_string = input('give me a number: ') # "1, 2, 3"
numbers = number_string.split(',')          #[1, 2, 3]
It's really overkill
input('give me a number: ').split(',')
Is functionally equivalent
Reply


Messages In This Thread
RE: [split] question about list comprehension - by Clunk_Head - Jan-12-2020, 04:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  List Comprehension Issue johnywhy 5 643 Jan-14-2024, 07:58 AM
Last Post: Pedroski55
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 533 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  Using list comprehension with 'yield' in function tester_V 5 1,355 Apr-02-2023, 06:31 PM
Last Post: tester_V
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,628 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  list comprehension 3lnyn0 4 1,490 Jul-12-2022, 09:49 AM
Last Post: DeaD_EyE
  Split string using variable found in a list japo85 2 1,363 Jul-11-2022, 08:52 AM
Last Post: japo85
  [split] [split] New to the forum, how to post a question? karnik 2 1,321 Feb-12-2022, 03:45 PM
Last Post: deanhystad
  List comprehension used differently coder_sw99 3 1,794 Oct-03-2021, 04:12 PM
Last Post: coder_sw99
  How to invoke a function with return statement in list comprehension? maiya 4 2,951 Jul-17-2021, 04:30 PM
Last Post: maiya
  List comprehension and Lambda cametan 2 2,294 Jun-08-2021, 08:29 AM
Last Post: cametan

Forum Jump:

User Panel Messages

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