About 426,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 - 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 …

  5. Print list without brackets in a single row - Stack Overflow

    Jun 24, 2012 · Python: How to print a list without quotations and square brackets. 3. howto print list without brackets ...

  6. python - How to convert list to string - Stack Overflow

    Apr 11, 2011 · Agree with @Bogdan. This answer creates a string in which the list elements are joined together with no whitespace or comma in between. You can use ', '.join(list1) to join the …

  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 do I get the last element of a list? - Stack Overflow

    Jun 14, 2019 · list[-1] will retrieve the last element of the list without changing the list. list.pop() will retrieve the last element of the list, but it will mutate/change the original list. Usually, mutating …

  9. In Python, is there an elegant way to print a list in a custom format ...

    Take a look on pprint, The pprint module provides a capability to “pretty-print” arbitrary Python data structures in a form which can be used as input to the interpreter. If the formatted …

  10. How do I get the length of a list? - Stack Overflow

    Nov 11, 2009 · Besides len you can also use operator.length_hint (requires Python 3.4+). For a normal list both are equivalent, but length_hint makes it possible to get the length of a list …

Refresh