Python Forum
Exclude words with specific endings from list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Exclude words with specific endings from list
#5
I replaced the content of my list #2 with the items ["aaa", "bbb", "ccc"] and excluded every word that ends with -b and -c. When i run the module, it still posts and alternates between all three items.

This is the whole script right now.

import random, time, tweepy, ast

with open('list1.txt') as infile:
    list1 = ast.literal_eval(infile.read())

with open('list2.txt') as infile:
    list2 = ast.literal_eval(infile.read())
    list2 = [item for item in list2 if not item.endswith("-b") and not item.endswith("-c")]

with open('list3.txt') as infile:
    list3 = ast.literal_eval(infile.read())

def one():
    return random.choice(list1) + random.choice(list2)

def two():
    return random.choice(list2) + random.choice(list3)

consumer_key = 'XXX'
consumer_secret = 'XXX'
access_token = 'XXX'
access_token_secret = 'XXX'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

while True:
    postthis = random.choice([one])()
    if len(postthis) <= 140:
        api.update_status(status=postthis)
        time.sleep(10)
Reply


Messages In This Thread
RE: Exclude words with specific endings from list - by Epileptiker - Apr-06-2018, 12:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Function to count words in a list up to and including Sam Oldman45 15 6,821 Sep-08-2023, 01:10 PM
Last Post: Pedroski55
  Regex Include and Exclude patterns in Same Expression starzar 2 863 May-23-2023, 09:12 AM
Last Post: Gribouillis
  [SOLVED] [loop] Exclude ranges in… range? Winfried 2 1,588 May-14-2023, 04:29 PM
Last Post: Winfried
  search a list or tuple for a specific type ot class Skaperen 8 2,029 Jul-22-2022, 10:29 PM
Last Post: Skaperen
Question How to gather specific second-level items from a list chatguy 2 1,598 Dec-17-2021, 05:05 PM
Last Post: chatguy
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 2,890 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  Telegram Users Scrapper - Exclude UserPrivacyRestricted graphite2015 0 2,646 Oct-23-2020, 05:43 AM
Last Post: graphite2015
  Remove specific elements from list with a pattern Xalagy 3 2,761 Oct-11-2020, 07:18 AM
Last Post: Xalagy
  Trying to find first 2 letter word in a list of words Oldman45 7 3,847 Aug-11-2020, 08:59 AM
Last Post: Oldman45
  how to check if string contains ALL words from the list? zarize 6 7,398 Jul-22-2020, 07:04 PM
Last Post: zarize

Forum Jump:

User Panel Messages

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