About 513,000 results
Open links in new tab
  1. How to print a list in Python "nicely" - Stack Overflow

    Aug 28, 2024 · For Python 3, I do the same kind of thing as shxfee's answer: def print_list(my_list): print('\n'.join(my_list)) a = ['foo', 'bar', 'baz'] print_list(a) which outputs. foo …

  2. python - Pythonic way to print list items - Stack Overflow

    Assuming you are using Python 3: print(*myList, sep='\n') This is a kind of unpacking. Details in the Python tutorial: Unpacking Argument Lists. You can get the same behavior on Python 2 …

  3. python - How to "properly" print a list? - Stack Overflow

    Mar 27, 2011 · If you're using a version of Python before 2.6, you'll need to use the string module's translate() function instead because the ability to pass None as the table argument …

  4. python - How do I get the last element of a list? - Stack Overflow

    Jun 14, 2019 · So lets consider that we have a list a = [1,2,3,4], in Python List can be manipulated to give us part of it or a element of it, using the following command one can easily get the last …

  5. python - How to print a list more nicely? - Stack Overflow

    Jun 16, 2015 · Update: Explanation as requested. Indexing. foolist[::3] selects every third element of foolist.foolist[1::3] selects every third element, starting at the second element ('1' because …

  6. python - How do I reverse a list or loop over it backwards? - Stack ...

    Oct 15, 2010 · I find (contrary to some other suggestions) that l.reverse() is by far the fastest way to reverse a long list in Python 3 and 2. I'd be interested to know if others can replicate these …

  7. Printing list elements on separate lines in Python

    Nov 25, 2023 · A list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default. As initialized …

  8. python - how to print a list like a string? - Stack Overflow

    Mar 24, 2018 · If you just want to print it, you can make use of the end parameter of print. It defaults to "\n" and is what is printed at the end of the string passed to it: for i in list: print(i, …

  9. python - f-string syntax for unpacking a list with brace suppression ...

    Mar 13, 2017 · print(f"Unpacked list: {*a,}") actually converts the list into a tuple, and unfortunately doesn't remove braces, it replaces them by parentheses and produces Unpacked list: (1, 2, 3). …

  10. python - Print list of lists in separate lines - Stack Overflow

    Iterate through every sub-list in your original list and unpack it in the print call with *: a = [[1, 3, 4], [2, 5, 7]] for s in a: print(*s) The separation is by default set to ' ' so there's no need to explicitly …

Refresh