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
Big Grin [solved] how to associate value in an array? paul18fr 9 3,709 Aug-26-2025, 05:44 AM
Last Post: paul18fr
  Convert nested sample json api data into csv in python shantanu97 3 6,933 May-21-2022, 01:30 PM
Last Post: deanhystad
  Python Regular expression, small sample works but not on file Acernz 5 5,271 Jun-09-2021, 08:27 PM
Last Post: bowlofred
  Syntax error in python code sample ErnestTBass 5 5,329 Aug-14-2020, 07:14 PM
Last Post: deanhystad
  Noob Question: Sample Data csn113 1 3,099 Feb-18-2019, 06:35 PM
Last Post: micseydel
  Final exam calculator iliketocode 1 5,149 Jan-08-2017, 07:06 PM
Last Post: ichabod801

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.