How do i make python choose randomly one line after the first line of a file?

Zehmy

Is it possible to make python to randomly choose a line EXCEPT the first line of the file which is reserved for something else? Any help appreciated :)

with open(filename + '.txt') as f:        
    lines = f.readlines()         
    answer = random.choice(lines) 
    print(answer)
Michael Bianconi

Slice the array:

answer = random.choice(lines[1:])

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

How do i make python choose randomly one line after the first line of a file?

How To Randomly Choose Strings From Same Line In File

How do I print the first line of a file after sorting without the last value in powershell?

How do I declare list in python using for loop in one line?

How to choose an imported python file by user's command line argument

How do I get this file the first number of each line to increment it? And what about the first line not being skipped? In C

How do I make sure the line that appears under the first column is moved to the second column on top

How to work on one line of a file at a time in python

How do I replace line-by-line text of a file in C?

How do I make my Print Statement print on only one line?

How to make line graph be one continuous line

How can I make a substitution on the line of first occurrence of a match only?

Python: How to print one more line after my result from file?

how can i view the first line of every file in my directory using python

How can i make a div and an anchor tag in one line

How to make first line of text file as header and skip second line in spark scala

How can I skip the first and the last line of a file in PHP

If I add the same product twice from a text file how do I output it one one line with the product price added together?

How do you read a text file into a dictionary with the information on one line separated by '\t' python

Regex: How to insert text before the first line and after the last line of file

How do I read two strings on each line, line by line, from a file in C

How do I loop though a text file, line by line, and append each line to an array?

How can i output more than one identical line from a csv file in python

How do I make cross line in tic tac toe

how can i make a sum in a line of numbers in python?

how to read text file line to line in python

How to match the string after first character in a line

Python: How do I do line continuation with a long regex?

How do I replace a line in a file using PowerShell?

TOP lista

  1. 1

    R Shiny: use HTML em funções (como textInput, checkboxGroupInput)

  2. 2

    O Chromium e o Firefox exibem as cores de maneira diferente e não sei qual deles está fazendo certo

  3. 3

    Como assinar digitalmente um documento PDF com assinatura e texto visíveis usando Java

  4. 4

    R Folheto. Dados de pontos de grupo em células para resumir muitos pontos de dados

  5. 5

    Gerenciar recurso shake de Windows Aero com barra de título personalizado

  6. 6

    Como obter dados API adequados para o aplicativo angular?

  7. 7

    UITextView não está exibindo texto longo

  8. 8

    Por que meus intervalos de confiança de 95% da minha regressão multivariada estão sendo plotados como uma linha de loess?

  9. 9

    Acessando relatório de campanhas na AdMob usando a API do Adsense

  10. 10

    Usando o plug-in Platform.js do Google

  11. 11

    Como posso modificar esse algoritmo de linha de visada para aceitar raios que passam pelos cantos?

  12. 12

    Dependência circular de diálogo personalizado

  13. 13

    Coloque uma caixa de texto HTML em uma imagem em uma posição fixa para site para desktop e celular

  14. 14

    iOS: como adicionar sombra projetada e sombra de traço no UIView?

  15. 15

    Como usar a caixa de diálogo de seleção de nomes com VBA para enviar e-mail para mais de um destinatário?

  16. 16

    Tabela CSS: barra de rolagem para a primeira coluna e largura automática para a coluna restante

  17. 17

    How to create dynamic navigation menu select from database using Codeigniter?

  18. 18

    Converter valores de linha SQL em colunas

  19. 19

    ChartJS, várias linhas no rótulo do gráfico de barras

  20. 20

    用@StyleableRes注释的getStyledAttributes。禁止警告

  21. 21

    não é possível adicionar dependência para com.google.android.gms.tasks.OnSuccessListener

quentelabel

Arquivo