Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
So I am new to python and I am trying to essentially "draw a board game", however I need it to print new lines with multiplication. This is my code so far:
x=int(input("How many columns? "))
y=int(input("How many rows? "))
z="|"
q="---"
f=((z + q)*x)+z
print(f*y)
What I want is to have newlines between rows, like this:
|---|---|---|
|---|---|---|
|---|---|---|
I tried:
print('\n', f,'\n', f, '\n', f)
How to put newlines between rows ?
If you just want spaces between rows, you can do:
print("\n\n".join([f]*y))
Upon decomposing:
[f] * y yields an array of rows
string.join(list) puts a string between each element in an list
So, you get two new lines between each row.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 months ago.
Improve this question
How can I multiply two elements in a list?
I am reading a text file, and printing the following:
for i in range(len(listeisotoper)):
print("Isotop type:"+listeisotoper[i][0])
print("Isotopisk masse u: "+listeisotoper[i][1])
print("Naturlig forekomst: "+listeisotoper[i][2])
print("xxx"+"g/mol")
print("\n")
However i cannot fathom how i can multiply the listeisotoper[i][1] * listeisotoper[i][2]
and then have it print the number with decimal points.
Any suggestions?
It isn't clear question for me, but may be this code will help you
for i in range(len(listeisotoper)):
print("Isotop type:"+listeisotoper[i][0])
print("Isotopisk masse u: "+listeisotoper[i][1])
print("Naturlig forekomst: "+listeisotoper[i][2])
mult_res = float(listeisotoper[i][1]) * float(listeisotoper[i][2])
print(f"Mult = {mult_res:.1f}")
print("xxx"+"g/mol")
print("\n")
I am assuming your problem is multiplying strings. If so, try this:
for i in range(len(listeisotoper)):
print("Isotop type:"+listeisotoper[i][0])
print("Isotopisk masse u: "+listeisotoper[i][1])
print("Naturlig forekomst: "+listeisotoper[i][2])
print(str(float(listeisotoper[i][1])*float(listeisotoper[i][2]))+"g/mol")
print("\n")
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Here is my Python script below but it just returning one of the lists. either it return 400k list of numbers or 16k list of numbers but it is not giving me a filterd result what am I doing wrong?
import os
# Read in the original and new file
orig = open('original.csv','r')
new = open('new.csv','r')
#in new but not in orig
bigb = set(new) - set(orig)
# To see results in console if desired
print(bigb)
# Write to output file
with open('different.csv', 'w') as file_out:
for line in bigb:
file_out.write(line)
#close the files
orig.close()
new.close()
file_out.close()
try in column C if column A is your list A and column B is your list B:
=FILTER(A:A; A:A<>""; NOT(REGEXMATCH(A:A&""; "^"&TEXTJOIN("$|^"; 1; B:B)&"$"))
update 1:
=INDEX(FILTER(A:A, NOT(COUNTIF(IFERROR(REGEXEXTRACT(
INDIRECT("B1:B"&MAX((B1:B<>"")*(ROW(B1:B))))&"", "\d+")*1), A:A))))
update 2:
=ARRAYFORMULA(QUERY(IFERROR(VLOOKUP(A1:A, {REGEXEXTRACT(
INDIRECT("B1:B"&MAX((B1:B<>"")*(ROW(B1:B))))&"", "\d+")*1, IF(
INDIRECT("B1:B"&MAX((B1:B<>"")*(ROW(B1:B))))="",,0)}, 2, 0), A1:A),
"where Col1 <> 0"))
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying to write a code that picks values in from a list to create to separate lists.
This is my code so far;
list = [6,2,9,10]
for x, y in zip(list, list):
print (x,y)
Output:
6,2
9,10
But what I want is:
[6,9]
[2,10]
You can zip slices of your original list to achieve your goal:
list = [6,2,9,10]
for x, y in zip(list[:2], list[2:]):
print (x,y)
6 9
2 10
This is not well-generalized - if you had a specific intent like "split my list into a first-half and second-half, and match the elements of those sub-lists" that would be more clear, but hopefully this helps you achieve what you want.
Assuming you want the elements at even index and odd index split into separate lists, you could do the following.
List1 =[1, 2,3,4,5]
even_list= List1[::2]
Odd_list = List1[1::2]
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a .txt file containing a list of lists, each list is a set of coordinates:
[[151.22999572753906, -33.84008789062494], [..., ...],... [..,..]]
I want to know how I can read this file as an array and not as a string so I can easily extract all the coordinates I need.
My code so far:
import re
d = '[[151.22999572753906, -33.84008789062494], [151.22999572753906, -33.84008789062494][151.22999572753906, -33.84008789062494]]'
##l = re.split('[\[\]]', d)
l = re.split('\]\[', d)
print(l)
>>>['[[151.22999572753906, -33.84008789062494], [151.22999572753906, -33.84008789062494', '151.22999572753906, -33.84008789062494]]']
It looks like the contents of your file happen to be valid JSON. If you're sure the format isn't going to vary, you can just use json.load
import json
json.loads('[[151.22999572753906, -33.84008789062494]]')
# or
json.load(open('/path/to/your.txt'))
[[151.22999572753906, -33.84008789062494]]
Start with
PSEUDOCODE
with open(.txt)
n = 0
while True
line = readline
n += 1
print(n , line)
How many Lines did you read?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a list of lists of strings such that:
decipher = [['###>>?', '######', '*&*...', '##&#&#'], ['###>>?', '######', '*&*...', '######'], ['###>>?', '######', '*&*...', '######'], ['###>>?', '######', '*&*...', '######']]
I need to concatenate items with the same indeces from each list to print on the same line, each subsequent set of identically indexed items have to print on a new line:
###>>?###>>?###>>?###>>?
########################
*&*...*&*...*&*...*&*...
##&#&###&#&###&#&###&#&#
How can I accomplish that? Thanks!
A simple one line solution would be:
>>> print '\n'.join(''.join(i) for i in zip(*decipher))
###>>?###>>?###>>?###>>?
########################
*&*...*&*...*&*...*&*...
##&#&###################
Here is another solution:
for col in range(len(decipher[0])):
out = ''
for row in range(len(decipher)):
out += decipher[row][col]
print(out)
###>>?###>>?###>>?###>>?
########################
*&*...*&*...*&*...*&*...
##&#&###################