r/learnpython • • Feb 20 '21

What are you having difficulty learning or are currently struggling to learn?

I'm curious what the community here has difficulty with when it comes to learning Python. Partly because I want to see if the more experienced community here (or myself) can help point you into the right direction. . . but also because I'm trying to come up with video tutorial ideas for future content and would love to hear from Python learners what would be most useful to dedicate our time on.

I'm looking forward to hearing what you guys have to say!

417 Upvotes

324 comments sorted by

View all comments

Show parent comments

2

u/keraj93 Feb 20 '21

I assume that the code is a part of a function, otherwise, the return statement will cause an error

if you iterate directly over the elements with for element in list1 then you don't need the indexor. You can use the ´elementto check the if statement, like this:if element in list2:and common_list.append(element).

Also a shortcut: intersection = list(set.intersection(set(list1), set(list2))) `

1

u/Athenas-Helm Feb 20 '21

Thats what I went for with my revision so good to know!

Thank you for the shortcut as well