Learn Python Coding
Learn Python through simple, practical examples and real coding ideas. Clear explanations, useful snippets, and hands-on learning for anyone starting or improving their programming skills. Admin: @HusseinSheikho || @Hussein_Sheikho
显示更多📈 Telegram 频道 Learn Python Coding 的分析概览
频道 Learn Python Coding (@pythonre) 英语 语言赛道中的 是活跃参与者。目前社区聚集了 39 129 名订阅者,在 技术与应用 类别中位列第 3 502,并在 印度 地区排名第 10 597 位。
📊 受众指标与增长动态
自 невідомо 创建以来,项目保持高速增长,吸引了 39 129 名订阅者。
根据 05 六月, 2026 的最新数据,频道保持稳定运转。过去 30 天订阅人数变化为 458,过去 24 小时变化为 21,整体触达仍然可观。
- 认证状态: 未认证
- 互动率 (ER): 平均受众互动率为 2.68%。内容发布后 24 小时内通常能获得 1.04% 的反应,占订阅者总量。
- 帖子覆盖: 每篇帖子平均可获得 1 048 次浏览,首日通常累积 405 次浏览。
- 互动与反馈: 受众积极参与,单帖平均反应数为 3。
- 主题关注点: 内容集中在 math, harvard, oxford, supervision, waybienad 等核心主题上。
📝 描述与内容策略
作者将该频道定位为表达主观观点的平台:
“Learn Python through simple, practical examples and real coding ideas. Clear explanations, useful snippets, and hands-on learning for anyone starting or improving their programming skills.
Admin: @HusseinSheikho || @Hussein_Sheikho”
凭借高频更新(最新数据采集于 07 六月, 2026),频道始终保持新鲜度与高覆盖。分析显示受众积极互动,使其成为 技术与应用 类别中的关键影响点。
abs() function. The abs() function returns the absolute value of any number (positive, negative, and complex). Below is shown how to get a list of absolute values from a list that contains both negative and positive numbers. We use list comprehension.
list1 = [-12, -45, -67, -89, 34, 67, -13]
print([abs(num) for num in list1])
[12, 45, 67, 89, 34, 67, 13]
Also, abs() can be applied to a floating-point number, and it will return the absolute value. See below:
num = -23.12
print(abs(num))
23.12
➡️ Using the math module
If you need more advanced mathematical functions, you can use fabs() from the math module. This function always returns a float.
import math
num = -23.12
absolute_value = math.fabs(num)
absolute_value
23.12
➡️ Using a lambda function
You can also use lambda to turn a negative number into its absolute value. The code below checks if x is less than zero (that is, if it's a negative value). If so, it returns -x, essentially removing the minus and making the number positive. If x is not negative (greater than or equal to 0), it returns x as it is.
num = -23.12
absolute_value = (lambda x: -x if x < 0 else x)(num)
absolute_value
23.12for loop, the second uses the itertools module, and the third uses list comprehension.
⚙️ Using a for loop:
For this method, we use a nested for loop. The outer loop iterates over the inner lists, and the inner loop accesses the elements in the inner lists.
# In [19]:
list1 = [[1, 2, 3],[4, 5, 6]]
newlist = []
for list2 in list1:
for j in list2:
newlist.append(j)
print(newlist)
[1, 2, 3, 4, 5, 6]
⚙️ Using the itertools module:
The itertools.chain.from_iterable() function from the itertools module can be used to flatten a nested list. This method may not be suitable for deeply nested lists.
# In [20]:
import itertools
list1 = [[1, 2, 3],[4, 5, 6]]
flat_list = list(itertools.chain.from_iterable(list1))
print(flat_list)
[1, 2, 3, 4, 5, 6]
You can see that the nested loop has been flattened.
⚙️ Using list comprehension
If you don't want to import itertools or write a regular for loop, you can simply use list comprehension.
# In [21]:
list1 = [[1, 2, 3], [4, 5, 6]]
flat_list = [i for j in list1 for i in j]
print(flat_list)
[1, 2, 3, 4, 5, 6]
List comprehension is well suited for moderately nested lists. For deeply nested lists, it is not suitable, as the code becomes harder to read.
⚙️ Using a generator function
You can create a generator function that yields elements from the nested list, and then convert the generator into a list.
# In [22]:
def flatten_generator(nested_list):
for sublist in nested_list:
for item in sublist:
yield item
list1 = [[1, 2, 3], [4, 5, 6]]
flat_list = list(flatten_generator(list1))
flat_list
Out[22]: [1, 2, 3, 4, 5, 6]
The generator method is suitable for flattening large or deeply nested lists. This is because generators are memory-efficient.
👉 https://t.me/DataScience4reversed() in Python - what supports it and what doesn't
The function reversed() is built-in in Python, but it doesn't work with all data types
✓ Lists - it works
reversed([1, 2, 3]) returns an iterator
list(reversed([1, 2, 3])) → [3, 2, 1]
✓ Tuples - it also works
reversed((1, 2, 3)) can be easily iterated
✗ Sets - not supported
reversed({1, 2, 3}) → TypeError
Why? Sets don't have a fixed order, so they can't be "reversed"
If you need to reverse a set:
list(reversed(list({1, 2, 3})))
# ❌ Bad: O(n²)
users = ["alice", "bob", "carol", "dave"]
for u in users:
if u in users: # full list traversal every time
process(u)
# ✅ Good: O(n)
users = ["alice", "bob", "carol", "dave"]
users_set = set(users)
for u in users:
if u in users_set:
process(u)Counter class from the collections module. Counter() returns a dictionary with the number of times each element appears in the sequence. Let's say we want to find out how many times the name Peter appears in the following list. We can use Counter(). See below:
from collections import Counter
list1 = ['John', 'Kelly', 'Peter', 'Moses', 'Peter']
count_peter = Counter(list1).get("Peter")
print(f'The name "Peter" appears in the list '
f'{count_peter} times.')
Output:
The name "Peter" appears in the list 2 times.
Another way to do this is with a regular for loop. We create a count variable and increase it by 1 each time we find the name Peter in the sequence. This is a naive approach. See below:
list1 = ['John', 'Kelly', 'Peter', 'Moses', 'Peter']
# Create a count variable
count = 0
for name in list1:
if name == 'Peter':
count +=1
print(f'The name "Peter" appears in the list'
f' {count} times.')
Output:
The name "Peter" appears in the list 2 times.
Lists and other iterable data structures in Python have a built-in count() method, which allows us to count the number of occurrences of a specific element. We can use count() to count how many times Peter appears in the list.
list1 = ['John', 'Kelly', 'Peter', 'Moses', 'Peter']
print(f'The name "Peter" appears in the list '
f'{list1.count("Peter")} times.')
Output:
The name "Peter" appears in the list 2 times.
👉 https://t.me/DataScience420 to the variable x and 30 to the variable y, and then swap them: x becomes 30, and y becomes 20. This method is called tuple packing/unpacking.
x, y = 20, 30
x, y = y, x
print('x is: ', x)
print('y is: ', y)
x is 30
y is 20
You can also use the XOR (exclusive or) operator to swap variables. This is a three-step method. In the example below, we swap the values of x and y.
x = 20
y = 30
# step one
x ^= y
# step two
y ^= x
# step three
x ^= y
print(f'x is: {x}')
print(f'y is: {y}')
x is: 30
y is: 20
You can also use arithmetic operations (addition and subtraction) to swap variables without a temporary variable. However, this method is recommended for swapping numeric data types. Here's an example:
# Use arithmetic operations
x = 5
y = 10
x = x + y
y = x - y
x = x - y
print("After swapping:")
print("x =", x)
print("y =", y)
After swapping:
x = 10
y = 5
As a result of these arithmetic operations, the values of x and y have actually been swapped. After the swap, x contains the original value of y (10), and y contains the original value of x (5).
This method of swapping variables without a temporary variable is based on the fact that when you add or subtract the value of one variable from another, you can effectively swap their values without the need for additional storage.
👉 https://t.me/DataScience4
现已上线!2025 年 Telegram 研究 — 年度关键洞察 
