Python Forum
Python institute associate sample exam question
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python institute associate sample exam question
#1
Can someone please explain the syntax and the logic of the below code? Especially the first line.

How many stars (*) will the following snippet send to the console?

lst = [[c for c in range(x)] for x in range(3)]
for x in lst:
     for y in x: if y < 2:
          print('*', end='')
Reply
#2
The first line is called a list comprehension. If you don't understand the rest of the code, how have you been learning?
Reply
#3
The rest I understand. Thanks. Will look into list comprehensions.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Convert nested sample json api data into csv in python shantanu97 3 2,838 May-21-2022, 01:30 PM
Last Post: deanhystad
  Python Regular expression, small sample works but not on file Acernz 5 2,943 Jun-09-2021, 08:27 PM
Last Post: bowlofred
  Syntax error in python code sample ErnestTBass 5 3,122 Aug-14-2020, 07:14 PM
Last Post: deanhystad
  Noob Question: Sample Data csn113 1 2,178 Feb-18-2019, 06:35 PM
Last Post: micseydel
  Final exam calculator iliketocode 1 3,912 Jan-08-2017, 07:06 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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