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

  5. 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 …

  6. 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, …

  7. Printing list elements on separate lines in Python

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

  8. python - Printing specific items out of a list - Stack Overflow

    for i in [2, 3]: print(li[i]) Note that indexes start at zero, so if you want to get the 3 and 4 you will need to access list indexes 2 and 3. You can also slice the list and iterate over the lists …

  9. python - How can I access the index value in a 'for' loop? - Stack …

    Breaking it down - a step by step explanation. To break these examples down, say we have a list of items that we want to iterate over with an index:

  10. writing a list to a txt file in python - Stack Overflow

    Dec 2, 2013 · In Python file objects are context managers which means they can be used with a with statement so you could do the same thing a little more succinctly with the following which …

Refresh