“co jest wyliczone w Pythonie” Kod odpowiedzi

Wylicz Pythona

languages = ["Python", "C", "C++", "C#", "Java"]
counter = 1

for item in languages:
    print(counter, item)
    counter += 1

for item in enumerate(languages):
    print(item[0], item[1])

for num,lang in enumerate(languages):
    print(num,lang)
    
[print(num,lang) for num,lang, in enumerate(languages)]
armin

Wylicz Pythona

animals = ["cat", "bird", "dog"]

#enumerate (For Index, Element)
for i, element in enumerate(animals,0):
    print(i, element)
    
for x in enumerate(animals):
    print(x, "UNPACKED =", x[0], x[1])
    
'''
0 cat
1 bird
2 dog
(0, 'cat') UNPACKED = 0 cat
(1, 'bird') UNPACKED = 1 bird
(2, 'dog') UNPACKED = 2 dog
'''
BreadCode

Python wylicz

'''
In python, you can use the enumerate function to add a counter to
your objects in a tuple or list.
'''

myAlphabet = ['a', 'b', 'c', 'd', 'e']
countedAlphabet = list(enumerate(myAlphabet)) # List turns enumerate object to list
print(countedAlphabet) # [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd'), (4, 'e')]

myList = ['cats', 'dogs', 'fish', 'birds', 'snakes']

for index, pet in enumerate(myList):
  print(index)
  print(pet)
Ninja Penguin

Python wylicz

# For loop where the index and value are needed for some operation

# Standard for loop to get index and value
values = ['a', 'b', 'c', 'd', 'e']
print('For loop using range(len())')
for i in range(len(values)):
    print(i, values[i])

# For loop with enumerate
# Provides a cleaner syntax
print('\nFor loop using builtin enumerate():')
for i, value in enumerate(values):
    print(i, value)

# Results previous for loops:
# 0, a
# 1, b
# 2, c
# 3, d
# 4, e

# For loop with enumerate returning index and value as a tuple
print('\nAlternate method of using the for loop with builtin enumerate():')
for index_value in enumerate(values):
    print(index_value)

# Results for index_value for loop:
# (0, 'a')
# (1, 'b')
# (2, 'c')
# (3, 'd')
# (4, 'e')
YEP Python

co jest wyliczone w Pythonie

df.iloc[:, np.r_[1:10, 15, 17, 50:100]]
Cooperative Civet

co jest wyliczone w Pythonie

np.r_[1:10, 15, 17, 50:100]

array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 15, 17, 50, 51, 52, 53, 54, 55,
       56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
       73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
       90, 91, 92, 93, 94, 95, 96, 97, 98, 99])
Cooperative Civet

Odpowiedzi podobne do “co jest wyliczone w Pythonie”

Pytania podobne do “co jest wyliczone w Pythonie”

Więcej pokrewnych odpowiedzi na “co jest wyliczone w Pythonie” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu