This question already has answers here:
Create an array with same element repeated multiple times
(25 answers)
Closed 7 years ago.
print "*" * 80
This is an elegant way to print delimiters (that has 80 astreisk symbols) in python log files. How can i do this in nodejs?
In node.js it is something like this:
console.log(new Array(80).join('*'));
Related
This question already has answers here:
Check if multiple strings exist in another string
(17 answers)
Closed 1 year ago.
a = '/dvi/abcbbb'
if ('/dev/' in a) or ('/dv/' in a) or ('/dvi/' in a):
print(a)
/dvi/abcbbb
Can we do it without the OR statements in Python ?
You can reverse the check:
if os.path.dirname(a) in ["/dev", "/dv", "/dvi"]:
print(a)
This question already has answers here:
How to change a string into uppercase?
(8 answers)
Closed 2 years ago.
What is the best pythonic way to covert, a string as '11-2020' to 'NOV-2020' in Python.
I tried below code :
print(datetime.datetime.strptime(date, '%m-%Y').strftime('%b-%Y'))
But getting output like : Nov-2020 (I want Nov to be in caps)
print(datetime.datetime.strptime(date, '%m-%Y').strftime('%b-%Y').upper())
#NOV-2020
This question already has answers here:
Slice every string in list in Python
(3 answers)
What is the purpose of the two colons in this Python string-slicing statement?
(1 answer)
Closed 4 years ago.
If i had a list as an example:
a = ['Hello_1.txt', 'Hello_2.txt']
In Python is it possible to somehow remove the first 5 characters ('Hello')
and the last 3 characters ('txt') from each of the items in the list ?
You could use a list-comprehension and string slicing:
[s[5:-3] for s in a]
which gives what you describe (not sure this is the neatest output though!)
['_1.', '_2.']
This question already has answers here:
Why does this code for initializing a list of lists apparently link the lists together? [duplicate]
(1 answer)
Why does appending to one list also append to all other lists in my list of lists? [duplicate]
(4 answers)
Python: fastest way to create a list of n lists
(5 answers)
Closed 4 years ago.
I don't know python I am working through 'Exercises in Programming Style' and translating to javascript. I can understand most of the python but this line flabbergasts me .
# Let's use the first 25 entries for the top 25 words
data = data + [[]]*(25 - len(data))
some context: the challenge is to use self imposed memory limitations represented here by the data array. So here she just cleared out data that is no longer used to make room for the 25 most frequent word. What is she doing here ?
This question already has answers here:
How do I split a list into equally-sized chunks?
(66 answers)
Closed 7 years ago.
Hello I am learning PYTHON and was learning about string splitting .so I have a hex string named
A="aca80202"
I want to convert it into a list of 2 characters
B=["ac","a8","02",02"]
is there any way to do it?
If you are starting with Python you could do it in a simple way using a for loop:
A="aca80202"
B = []
for i in range(0, len(A), 2):
B.append(A[i:i+2])
EDIT: you could see more ways to do it here.