Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
removing item
#1
I have a question, is it possible to remove a string in a list, if the same string also exists in a file, by using a code?

If yes, how can i do that?
Reply
#2
Open the file
Until you reach end of file, read a string
See if string is in the list
If yes, remove the string from the list

What have you done so far?
Reply
#3
Hello, I have a list: list = ['1', '2']
in my txt file i have only written the number 2 in the first line.

so i actually want to make a code that reads the txt file, and if the string in the txt file also excists in the list i made, i want it to delete it out of the list.. so if i print list after it removed it should print out only ['1']
Reply
#4
Solve this problem first.
a = [1, 2, 3, 4, 5]
From a remove 2

Once you can solve that problem solve this problem:
a = [1, 2, 3, 4, 5]
b = [2, 4, 6]
From a remove any number that is in b.

Once you solve that problem solve this problem:
Make a list of all numbers contained in file b.

And finally:
a = [1, 2, 3, 4, 5]
From a remove any number that is in file b.
pastakipp likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  change item in column based on the item before[solved] amdi40 4 1,826 Jan-11-2022, 04:50 PM
Last Post: amdi40
  need help removing an item from a list jhenry 4 4,251 Oct-13-2017, 08:15 AM
Last Post: buran

Forum Jump:

User Panel Messages

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