Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List and loop
#4
(Oct-23-2019, 07:27 AM)woooee Wrote: If you want items in both lists, use set union https://www.programiz.com/python-programming/set#union
Thank you for suggesting better ways. I know there are many ways to do this simple task.
But can i expect that output from code above? Can you see if there is something wrong with the code itself.

Sorry i misplaced plist and qlist.
phrase="don't panic"
plist=list(phrase)
str1="on tap"
qlist=list(str1)
for item in plist:
    if item not in qlist:
        plist.remove(item)
print(plist)
Reply


Messages In This Thread
List and loop - by Sandeep2000 - Oct-23-2019, 05:53 AM
RE: List and loop - by buran - Oct-23-2019, 05:54 AM
RE: List and loop - by woooee - Oct-23-2019, 07:27 AM
RE: List and loop - by Sandeep2000 - Oct-23-2019, 07:44 AM
RE: List and loop - by Gribouillis - Oct-23-2019, 08:48 AM
RE: List and loop - by perfringo - Oct-23-2019, 08:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Appending to list of list in For loop nico_mnbl 2 2,385 Sep-25-2020, 04:09 PM
Last Post: nico_mnbl
  Append list into list within a for loop rama27 2 2,418 Jul-21-2020, 04:49 AM
Last Post: deanhystad
  loop through list or double loop 3Pinter 4 3,478 Dec-05-2018, 06:17 AM
Last Post: 3Pinter
  Write a for loop on list of lists without changing the shape of the main list Antonio 3 3,788 Jun-19-2018, 02:16 AM
Last Post: ichabod801
  For looping over a list, editing the list from inside the loop? Krookroo 3 3,978 Sep-04-2017, 05:08 PM
Last Post: Krookroo
  How to change from printFacts ( ) to return a list & Loop over list when writing CSV Ivan1 14 8,403 Aug-30-2017, 12:14 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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