[Tutor] adding users to tweets on a list
Chris Down
chris at chrisdown.name
Tue Aug 6 11:15:23 CEST 2013
On 2013-08-06 03:48, Saad Javed wrote:
> I want to add users to the tweet from the list, the no. of users added
> based on the length of the tweet.
It looks like you're using Python 2, but you didn't specify.
I'd probably do something like this:
#!/usr/bin/env python
MAX_LENGTH = 140
users = [
"saad", "asad", "sherry", "danny", "ali", "hasan", "adil", "yousaf",
"maria", "bilal", "owais",
]
def populate():
message = raw_input("Enter string: ")
while users:
new_message = " ".join([message, "@" + users.pop(0)])
if len(new_message) > MAX_LENGTH:
break
message = new_message
return message
if __name__ == "__main__":
print(populate())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20130806/eed1d8c3/attachment.pgp>
More information about the Tutor
mailing list