Telegram Group & Telegram Channel
Что выведет этот код?

Могло показаться, что выведется словарь с буквами и их повторением в словаре.

dict.setdefault(key, default=None) - возвращает значение по ключу key, а если ключа нет в словаре, то добавляет пару key=default и возвращает значение default.

dict.get(key, default=None) - возвращает значение по ключу key, а если ключа нет, то возвращает default не добавляя пару в словарь.

То есть мы просто каждой букве в слове поставили значение counter.get(char, 1) + 1 = 2.

Чтобы посчитать реальный счетчик повторении есть несколько способов:


s = "hello"

# 1
counter = {}
for char in s:
counter[char] = counter.setdefault(char, 0) + 1

# 2
counter = {}
for char in s:
counter[char] = counter.get(char, 0) + 1

# 3
from collections import defaultdict
counter = defaultdict(int)
for char in s:
counter[char] += 1

# 4
from collections import Counter
counter = Counter(s)


#dict #counter



tg-me.com/pythrone/13
Create:
Last Update:

Что выведет этот код?

Могло показаться, что выведется словарь с буквами и их повторением в словаре.

dict.setdefault(key, default=None) - возвращает значение по ключу key, а если ключа нет в словаре, то добавляет пару key=default и возвращает значение default.

dict.get(key, default=None) - возвращает значение по ключу key, а если ключа нет, то возвращает default не добавляя пару в словарь.

То есть мы просто каждой букве в слове поставили значение counter.get(char, 1) + 1 = 2.

Чтобы посчитать реальный счетчик повторении есть несколько способов:


s = "hello"

# 1
counter = {}
for char in s:
counter[char] = counter.setdefault(char, 0) + 1

# 2
counter = {}
for char in s:
counter[char] = counter.get(char, 0) + 1

# 3
from collections import defaultdict
counter = defaultdict(int)
for char in s:
counter[char] += 1

# 4
from collections import Counter
counter = Counter(s)


#dict #counter

BY PyThrone




Share with your friend now:
tg-me.com/pythrone/13

View MORE
Open in Telegram


telegram Telegram | DID YOU KNOW?

Date: |

Look for Channels Online

You guessed it – the internet is your friend. A good place to start looking for Telegram channels is Reddit. This is one of the biggest sites on the internet, with millions of communities, including those from Telegram.Then, you can search one of the many dedicated websites for Telegram channel searching. One of them is telegram-group.com. This website has many categories and a really simple user interface. Another great site is telegram channels.me. It has even more channels than the previous one, and an even better user experience.These are just some of the many available websites. You can look them up online if you’re not satisfied with these two. All of these sites list only public channels. If you want to join a private channel, you’ll have to ask one of its members to invite you.

The STAR Market, as is implied by the name, is heavily geared toward smaller innovative tech companies, in particular those engaged in strategically important fields, such as biopharmaceuticals, 5G technology, semiconductors, and new energy. The STAR Market currently has 340 listed securities. The STAR Market is seen as important for China’s high-tech and emerging industries, providing a space for smaller companies to raise capital in China. This is especially significant for technology companies that may be viewed with suspicion on overseas stock exchanges.

telegram from in


Telegram PyThrone
FROM USA