EverythingPython

List comprehension tuples and obj equals

2 Quick TILs today -

  1. You cannot use a tuple in a list comprehension without params - Alt Text

The correct syntax is [(i,j) for i in a for j in b

  1. The usage of obj= within a formatted string during printing results in both the object’s name as well its value separated by an “=” being printed -

In the imge below, a is a list as used earlier. Therefore -

Alt Text

  1. WIP