Python Forum
Syntax when initializing empty lists
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax when initializing empty lists
#1
Hi all,

I have two questions with regard to initializing empty lists. This works:

list_a, list_b, list_c = ([] for i in range(3))
What exactly do the parentheses mean on the right? Without them I get a syntax error. With them, though, I don't recognize what kind of statement it makes. For example, it's not a list comprehension as that would be in brackets.

Second, on the left if I use equals signs instead of commas, then I get all three labels pointing to a generator object. Why?
Reply


Messages In This Thread
Syntax when initializing empty lists - by Mark17 - Jun-01-2022, 05:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Auto-py-to-exe Stuck At 'Initializing' killingtime 5 7,029 Jan-21-2024, 10:52 PM
Last Post: ShiDari
  "unexpected keyword arg" when initializing my subclasses Phaze90 3 3,178 Nov-25-2022, 07:39 PM
Last Post: Gribouillis
  Initializing a PRINTDLG structure-how to hammer 4 1,505 Jun-08-2022, 07:07 PM
Last Post: jefsummers
  Initializing, reading and updating a large JSON file medatib531 0 1,798 Mar-10-2022, 07:58 PM
Last Post: medatib531
  Lists + Empty Lists Pytho13 15 5,554 Mar-26-2021, 08:52 PM
Last Post: pythonprogrammer1101935
  Append 2d empty lists NMMST 2 2,917 Oct-19-2020, 09:25 PM
Last Post: NMMST
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,387 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  Lists first item is a number however i cant compare it with an int getting syntax err Sutsro 4 2,434 Apr-22-2020, 10:22 AM
Last Post: Sutsro
  Self re-initializing variable? python_user_n 6 3,211 May-03-2019, 02:52 PM
Last Post: Gribouillis
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,291 Mar-20-2019, 08:01 PM
Last Post: stillsen

Forum Jump:

User Panel Messages

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