r/Python • u/Perfect-Lab-9681 • May 08 '23
Resource How do I concatenate two lists in Python?
https://codingfunction.com/posts/how-do-i-concatenate-two-lists-in-python18
u/pythonHelperBot May 08 '23
Hello! I'm a bot!
It looks to me like your post might be better suited for r/learnpython, a sub geared towards questions and learning more about python regardless of how advanced your question might be. That said, I am a bot and it is hard to tell. Please follow the subs rules and guidelines when you do post there, it'll help you get better answers faster.
Show /r/learnpython the code you have tried and describe in detail where you are stuck. If you are getting an error message, include the full block of text it spits out. Quality answers take time to write out, and many times other users will need to ask clarifying questions. Be patient and help them help you. Here is HOW TO FORMAT YOUR CODE For Reddit and be sure to include which version of python and what OS you are using.
You can also ask this question in the Python discord, a large, friendly community focused around the Python programming language, open to those who wish to learn the language or improve their skills, as well as those looking to help others.
README | FAQ | this bot is written and managed by /u/IAmKindOfCreative
This bot is currently under development and experiencing changes to improve its usefulness
17
u/glenbolake May 08 '23
The issue I take with this article is that itertools.chain doesn't return a list; it returns a generator.
Also, I sometimes like using unpacking to concatenate (not often, but sometimes). [*list1, *list2] can be easier to read on occasion.
7
3
4
-1
-7
u/PolyglotTV May 08 '23
I just asked ChatGPT to write an article about the various ways to add 2 numbers in Python. It came up with a list of 5 different methods and code snippets of each. Looked exactly like this and many other articles posted here recently.
FYI In case you are curious the 5 methods it came up with:
The
+Operatorsumfunctionmath.fsumUsing a lambda (rolls eyes)
operator.add
7
u/witchfinder_sergeant May 08 '23
Well it looks liek CHatGPT has really outdone itself this time by providing us with such groundbreaking information on adding two numbers in Python! I would've never thought of the + operator /s
-1
May 08 '23
Lol, maybe I should define a custom data class that has a custom “add_other_list” method. Then instantiate that thing twice, one for each list, and then call the method.
0
0
0
8
0
May 08 '23
[deleted]
1
u/PaluMacil May 08 '23
You're responding to somebody who wrote an article on this topic, not someone asking a question, so I'm guessing it won't save them any time. Now are there already several hundred articles covering this? Probably...
-1
52
u/[deleted] May 08 '23
Use the + operator.