IntStream.rangeClosed(1, n).forEach(i -> {
IntStream.rangeClosed(1, n).forEach(j ->
System.out.print((i + j) % 2 == 0 ? '*' : '-'));
System.out.println();});
IntStream.rangeClosed(1, n*n).forEach(i -> System.out.print(i % n != 0 ? (i % 2==0 ?'*':'-') : '\n'));
//// users/users.go
package users
type user struct {
name string
}
func New(name string) *user {
u := user{
name: name,
}
if name == "" {
u.name = "Nobody"
}
return &u
}
///// main.go
package main
import "github.com/yourproject/users"
func main() {
user := users.New("")
...........
}
data = {
'user': [
{'name': 'Alex', 'age': 18},
{ 'name': 'Jack', 'age': 23},
{'name': 'Anna', 'age': 17}
]
}
# Способ 1
names = []
for user in data['user']:
names.append(user['name'])
print(names)
# Способ 2
names = [user['name'] for user in data['user']]
print(names)
# Способ 3
names = list(map(lambda x: x['name'], data['user']))
print(names)
# Выбирайте, какой вам больше по душе