How to print a list of numbers without square brackets?

2024/10/12 6:22:44

I'm generating a list of random digits, but I'm struggling to figure out how to output the digits in a single row without the square brackets?

import random 
def generateAnswer(answerList):listofDigits = []while len(listofDigits) < 5:digit = random.randint(1, 9)if digit not in listofDigits:listofDigits.append(digit)return listofDigitsdef main():listofDigits = []print(generateAnswer(listofDigits))main()
Answer

You can unpack a list and use the sep argument:

print(*generateAnswer(listofDigits), sep=' ')
https://en.xdnf.cn/q/118229.html

Related Q&A

How to save plotly offline by running my script

I am using below code in my jupyter notebook.import pandas as pd import numpy as np %matplotlib inlinefrom plotly import __version__ from plotly.offline import download_plotlyjs, init_notebook_mode, pl…

Same output of the Keras model

I have a Keras model for predicting moves in the game. I have an input shape of (160,120 ,1). I have the following model with an output of 9 nodes:from keras.models import Sequential from keras.layers.…

Extract common element from 2 tuples python [duplicate]

This question already has answers here:Find intersection of two nested lists?(21 answers)Is there a way to get the difference and intersection of tuples or lists in Python? [duplicate](1 answer)Close…

How to make an integer index row?

I have a DataFrame: +-----+--------+---------+ | usn|log_type|item_code| +-----+--------+---------+ | 0| 11| I0938| | 916| 19| I0009| | 916| 51| I1097| | 916| 19| …

Matplotlib plt.plot with enumerate not working

import numpy as np import matplotlib.pyplot as plt array = np.array([[1,2,3,4,5,6],[10,20,30,40,50,60],[3,4,5,6,7,8],[100,200,300,400,500,600]])def plot(list):fig = plt.figure()ax = fig.add_subplot(11…

using complex conditions to form a pandas data frame from the existing one

Ive got the following dataframe containing function names, their arguments, the default values of the arguments and argument types:FULL_NAME ARGUMENT DEF_VALS TYPE function1 f1_arg1 NAN …

Crawl and scrape a complete site with scrapy

import scrapy from scrapy import Request#scrapy crawl jobs9 -o jobs9.csv -t csv class JobsSpider(scrapy.Spider): name = "jobs9" allowed_domains = ["vapedonia.com"] start_urls = [&qu…

Why is pip freezing and not showing a module, although pip install says its already installed?

Im following these instructions to install Odoo on Mac. It required that I install all the Python modules for the user like so: sudo pip install -—user -r requirements.txt(*A note about the --user par…

Flatten a list of strings which contains sublists

I have a list of strings which contains a sublist os strings:ids = [uspotify:track:3ftnDaaL02tMeOZBunIwls, uspotify:track:4CKjTXDDWIrS0cwSA9scgk, [uspotify:track:6oRbm1KOqskLTFc1rvGi5F, uspotify:track:…

Portscanner producing possible error

I have written a simple portscanner in python. I have already asked something about it, you can find the code here.I corrected the code and now am able to create a connection to e.g. stackoverflow.netB…