This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Hello there, I'm a Python beginner going through the Automate the Boring Stuff, already through the Automation Stuff.
I went through the Regular Expression Basics tutorial and thought of a code that along with identifying useful numbers/codes would output copyable columns. Found the columnar module and got into it.
I got this code, which is partly the one from the tutorial.
import re
from columnar import columnar
message=('Call me 415-555-1011 tomorrow, or at 415-555-9999 any other day. 378-123-4432 for reservations, 234-554-1234 for whatever. ')
phoneNumRegex= re.compile(r'\d\d\d-\d\d\d-\d\d\d\d')
print(phoneNumRegex.findall(message))
phoneNumbers=(phoneNumRegex.findall(message))
phoneNumbersList=[(phoneNumRegex.findall(message))]
headers = ['']
for i in phoneNumbers:
headers.append('')
table = columnar(phoneNumbersList, headers, no_borders=True)
print(table)
# print(phoneNumbers)
# print(headers)
# print(len(phoneNumRegex.findall(message)))
The output I get is
['415-555-1011', '415-555-9999', '378-123-4432', '234-554-1234']
415-555-1011 415-555-9999 378-123-4432 234-554-1234
I would like for it to be displayed in rows in a single column instead of a column for each.
If along with that the output could be copypasted into Excel sheets (it fitting the rows instead of filling a single cell) this could be the basis of an applicable shortcut for work.
I suspect this is gonna explained further into the course, but I'm curious about asking it now.
Thanks.
Subreddit
Post Details
- Posted
- 3 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnpython...