let' have look at one of those common operationsnamelyconverting list of items into list of related items specificallylet' assume we just read list of strings from fileand now we want to convert it to list of integers we know every item in the list is an integerand we want to do some activity (saycalculate an averageon those numbers here' one simple way to approach itinput_strings [' '' '' '' '' 'output_integers [for num in input_stringsoutput_integers append(int(num)this works fine and it' only three lines of code if you aren' used to comprehensionsyou may not even think it looks uglynowlook at the same code using list comprehensioninput_strings [' '' '' '' '' ']output_integers [int(numfor num in input_stringswe're down to one line andimportantly for performancewe've dropped an append method call for each item in the list overallit' pretty easy to tell what' going oneven if you're not used to comprehension syntax the square brackets indicateas alwaysthat we're creating list inside this list is for loop that iterates over each item in the input sequence the only thing that may be confusing is what' happening between the list' opening brace and the start of the for loop whatever happens here is applied to each of the items in the input list the item in question is referenced by the num variable from the loop soit' converting each individual element to an int data type that' all there is to basic list comprehension they are not so advanced after all comprehensions are highly optimized codelist comprehensions are far faster than for loops when looping over huge number of items if readability alone isn' convincing reason to use them as much as possiblespeed should be converting one list of items into related list isn' the only thing we can do with list comprehension we can also choose to exclude certain values by adding an if statement inside the comprehension have lookoutput_ints [int(nfor in input_strings if len(